Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用数组创建VBA图表_Vba_Excel - Fatal编程技术网

使用数组创建VBA图表

使用数组创建VBA图表,vba,excel,Vba,Excel,我正在尝试使用vb6创建excel图表。我没有输入excel范围,而是尝试输入数组。我得到一个错误。 这是我正在编写的代码 Private Sub CreateChart(Optional ByVal ChartTitle As String _ , Optional ByVal xAxis As Excel.Range _ , Optional ByVal yAxis As Excel.Range _

我正在尝试使用vb6创建excel图表。我没有输入excel范围,而是尝试输入数组。我得到一个错误。 这是我正在编写的代码

Private Sub CreateChart(Optional ByVal ChartTitle As String _
                , Optional ByVal xAxis As Excel.Range _
                , Optional ByVal yAxis As Excel.Range _
                , Optional ByVal ColumnName As String _
                , Optional ByVal LegendPosition As XlLegendPosition = xlLegendPositionRight _
                , Optional ByVal rowIndex As Long = 2 _
                , Optional ByRef ChartType As String = xlLineMarkers _
                , Optional ByVal PlotAreaColorIndex As Long = 2 _
                , Optional ByVal isSetLegend As Boolean = False _
                , Optional ByVal isSetLegendStyle As Boolean = False _
                , Optional ByVal LegendStyleValue As Long = 1)

Const constChartLeft = 64
Const constChartHeight = 300
Const constChartWidth = 700

Dim xlChart As Excel.ChartObject
Dim seriesCount As Long
Dim ColorIndex As Long

Dim j As Long


With mWorksheet
    .Rows(rowIndex).RowHeight = constChartHeight

    Set xlChart = .ChartObjects.Add(.Rows(rowIndex).Left, .Rows(2).Top, constChartWidth, constChartHeight)
End With

With xlChart.chart
    .ChartType = ChartType
    .SetSourceData Source:=marrayPOClient, PlotBy:=marrayPOSKU
    .SeriesCollection(1).XValues = marrayPOClient
    .HasTitle = True

    .Legend.Position = LegendPosition
    .Legend.Font.Size = 7.3
    .Legend.Font.Bold = True
    .Legend.Border.LineStyle = xlNone

    .ChartTitle.Characters.Text = ChartTitle
    .ChartTitle.Font.Bold = True

    .Axes(xlValue).TickLabels.Font.Size = 8 ' yAxis Labels
    .Axes(xlCategory).TickLabels.Font.Size = 8 ' xAxis Labels

    .PlotArea.Interior.ColorIndex = PlotAreaColorIndex
    .PlotArea.Interior.ColorIndex = 15
    .PlotArea.Interior.PatternColorIndex = 1
    .PlotArea.Interior.Pattern = xlSolid
End With
End Sub
是否可以将数组用于图表。如果可能,我的错误是什么。

要求其
参数使用
范围
对象,其
绘图方式
参数使用
XlRowCol
枚举值


假设
marrayPOClient
marrayPOSKU
都是其名称所暗示的数组(您没有显示它们的声明位置和分配方式,因此我们无法知道它们的类型或值),但您需要为第一个参数提供一个
范围,并且可以选择,第二个参数可以是
xlColumns
xlRows

正如Mat的杯子所说,
SetSourceData
需要一个
范围,但可以使用另一种方法获得结果

替换

.SetSourceData Source:=marrayPOClient, PlotBy:=marrayPOSKU


这将创建一个没有源的新序列,然后将数组指定为序列值,我将得到一个错误-告诉我们您得到的确切错误将非常有用。@Mat'sMug它说“需要对象”很好,这是一个开始。。。是否突出显示了一行代码或特定函数调用?@Mat'smugh这行代码中出现了错误
。SetSourceData:=marrayPOClient,PlotBy:=marrayPOSKU
请注意,如果使用数组,它可以包含的数据量是有限的,因为你受到级数公式最大长度的限制,我也是这么想的。还有别的办法吗?我尝试使用
chart.values
,但仍然失败。错误为“无效参数”
.SeriesCollection.NewSeries
.SeriesCollection(1).Values = marrayPOClient