Vba Excel源数据错误方向

Vba Excel源数据错误方向,vba,excel,graph,Vba,Excel,Graph,我在.SeriesCollection(1)行获取的参数无效。MarkerStyle=xlmarkerstylecycle 问题是,我的源数据似乎不起作用,或者说,确实起作用,但不像我想的那样 我无法添加图片,因此我将尽我所能描述正在发生的事情以及我正在寻找的内容 为了帮忙,这里有一张桌子 3 season A col B col C col D col E col F col G 4 2010 - 2011 9,66 1,25 10,9

我在
.SeriesCollection(1)行获取的参数无效。MarkerStyle=xlmarkerstylecycle

问题是,我的源数据似乎不起作用,或者说,确实起作用,但不像我想的那样

我无法添加图片,因此我将尽我所能描述正在发生的事情以及我正在寻找的内容

为了帮忙,这里有一张桌子

3    season A      col B  col C col D    col E   col F   col G
4    2010 - 2011       9,66   1,25  10,9    10175   20837   31012
5    2011 - 2012       7,34   0,62  8       8110    21884   29994
6    2012 - 2013       7,84   0,18  8       6840    17943   24783
哪个
季节计数=3

我所拥有的:系列是横向的,取决于季节的数量。就像上面这张表一样,我得到了3个系列的集合。对于这个表,
系列集合(1)是D4:G4

我想要的是垂直系列,SourceData是“D4:G”和季节计数+3,这将是D4到G6。使用
SeriesCollection(1)=“D4:D6”
I然后删除对应于列E和列F的集合,现在
SeriesCollection(2)=“G4:G6”

编辑**

我之前无法添加图片,但现在可以了。结果如下:

这是另一个工作非常好的表,正如您所看到的,代码中没有太多更改。区别在于
季节计数
变量和X轴现在是列A而不是列B这一事实

工作代码和图形:

With ActiveSheet.ChartObjects.Add _
        (Left:=10, Width:=480, Top:=240, Height:=265)
    With .Chart
        .ChartType = xlLineMarkers

        .SetSourceData Source:=Sheets("Results").Range("E4:H10")


        .SeriesCollection(1).XValues = Sheets("Results").Range("B4:B10")
        .SeriesCollection(1).Name = "Indice de rigueur hivernale"
        .SeriesCollection(1).MarkerStyle = xlMarkerStyleCircle
        .SeriesCollection(1).Format.Line.Weight = 4
        .SeriesCollection(1).Border.Weight = 0.75

        .SeriesCollection(2).Delete
        .SeriesCollection(2).Delete

        .SeriesCollection(2).ChartType = xlColumnClustered
        .SeriesCollection(2).AxisGroup = 2
        .SeriesCollection(2).Name = "Consommation de sel totale"

        With .SeriesCollection(2).Format.Line
            .Visible = msoTrue
            .ForeColor.ObjectThemeColor = msoThemeColorBackground1
            .ForeColor.TintAndShade = 0
            .ForeColor.Brightness = -0.349999994
            .Transparency = 0
        End With
        With .SeriesCollection(2).Format.Fill
            .Visible = msoTrue
            .ForeColor.ObjectThemeColor = msoThemeColorBackground1
            .ForeColor.TintAndShade = 0
            .ForeColor.Brightness = -0.25
            .Transparency = 0
            .Solid
        End With

        .SetElement (msoElementChartTitleAboveChart)
        .SetElement (msoElementLegendBottom)
        .SetElement (msoElementPrimaryValueAxisTitleRotated)
        .SetElement (msoElementSecondaryValueAxisTitleRotated)
        .Axes(xlValue, xlPrimary).AxisTitle.Text = "Indice de rigueur hivernale"
        .Axes(xlValue, xlSecondary).AxisTitle.Text = "Consommation de sel (tonnes)"
        .ChartStyle = 19
        .ChartTitle.Text = "Indice par rapport au sel total"
    End With
End With


多亏了@Byron Wall,用
.SeriesCollection.NewSeries
而不是
.SetSourceData
手动创建系列效果非常好。这是工作代码

With ActiveSheet.ChartObjects.Add _
        (Left:=10, Width:=480, Top:=240, Height:=265)
    With .Chart
        .ChartType = xlLineMarkers

        .SeriesCollection.NewSeries
        .SeriesCollection(1).Values = Sheets("Results").Range("D4:D" & seasonCount + 3)
        .SeriesCollection(1).XValues = Sheets("Results").Range("A4:A" & seasonCount + 3)
        .SeriesCollection(1).Name = "Indice de rigueur hivernale"
        .SeriesCollection(1).MarkerStyle = xlMarkerStyleCircle
        .SeriesCollection(1).Format.Line.Weight = 4
        .SeriesCollection(1).Border.Weight = 0.75

        .SeriesCollection.NewSeries
        .SeriesCollection(2).Values = Sheets("Results").Range("G4:G" & seasonCount + 3)
        .SeriesCollection(2).ChartType = xlColumnClustered
        .SeriesCollection(2).AxisGroup = 2
        .SeriesCollection(2).Name = "Consommation de sel totale"

        With .SeriesCollection(2).Format.Line
            .Visible = msoTrue
            .ForeColor.ObjectThemeColor = msoThemeColorBackground1
            .ForeColor.TintAndShade = 0
            .ForeColor.Brightness = -0.349999994
            .Transparency = 0
        End With
        With .SeriesCollection(2).Format.Fill
            .Visible = msoTrue
            .ForeColor.ObjectThemeColor = msoThemeColorBackground1
            .ForeColor.TintAndShade = 0
            .ForeColor.Brightness = -0.25
            .Transparency = 0
            .Solid
        End With

        .SetElement (msoElementChartTitleAboveChart)
        .SetElement (msoElementLegendBottom)
        .SetElement (msoElementPrimaryValueAxisTitleRotated)
        .SetElement (msoElementSecondaryValueAxisTitleRotated)
        .Axes(xlValue, xlPrimary).AxisTitle.Text = "Indice de rigueur hivernale"
        .Axes(xlValue, xlSecondary).AxisTitle.Text = "Consommation de sel (tonnes)"
        .ChartStyle = 19
        .ChartTitle.Text = "Indice par rapport au sel total"
    End With
End With

为什么你不能添加一张图片?你有代表。数据敏感吗?如果是这样的话,你能把它弄得乱七八糟吗?我看不出有什么明显的理由认为电话会在那里失败。如果要更好地控制
系列
,应使用
系列集合.NewSeries
并手动将
XValues
设置为所需的
范围
。它提供了比
SetSourceData
更大的控制。如果你把那行注释掉,它是否正确运行。。。还是比那一行出错更多?您需要在
SetSourceData
中使用
PlotBy
,就像在
中一样。SetSourceData源:=\u范围,PlotBy:=xlColumns
With ActiveSheet.ChartObjects.Add _
        (Left:=10, Width:=480, Top:=240, Height:=265)
    With .Chart
        .ChartType = xlLineMarkers

        .SeriesCollection.NewSeries
        .SeriesCollection(1).Values = Sheets("Results").Range("D4:D" & seasonCount + 3)
        .SeriesCollection(1).XValues = Sheets("Results").Range("A4:A" & seasonCount + 3)
        .SeriesCollection(1).Name = "Indice de rigueur hivernale"
        .SeriesCollection(1).MarkerStyle = xlMarkerStyleCircle
        .SeriesCollection(1).Format.Line.Weight = 4
        .SeriesCollection(1).Border.Weight = 0.75

        .SeriesCollection.NewSeries
        .SeriesCollection(2).Values = Sheets("Results").Range("G4:G" & seasonCount + 3)
        .SeriesCollection(2).ChartType = xlColumnClustered
        .SeriesCollection(2).AxisGroup = 2
        .SeriesCollection(2).Name = "Consommation de sel totale"

        With .SeriesCollection(2).Format.Line
            .Visible = msoTrue
            .ForeColor.ObjectThemeColor = msoThemeColorBackground1
            .ForeColor.TintAndShade = 0
            .ForeColor.Brightness = -0.349999994
            .Transparency = 0
        End With
        With .SeriesCollection(2).Format.Fill
            .Visible = msoTrue
            .ForeColor.ObjectThemeColor = msoThemeColorBackground1
            .ForeColor.TintAndShade = 0
            .ForeColor.Brightness = -0.25
            .Transparency = 0
            .Solid
        End With

        .SetElement (msoElementChartTitleAboveChart)
        .SetElement (msoElementLegendBottom)
        .SetElement (msoElementPrimaryValueAxisTitleRotated)
        .SetElement (msoElementSecondaryValueAxisTitleRotated)
        .Axes(xlValue, xlPrimary).AxisTitle.Text = "Indice de rigueur hivernale"
        .Axes(xlValue, xlSecondary).AxisTitle.Text = "Consommation de sel (tonnes)"
        .ChartStyle = 19
        .ChartTitle.Text = "Indice par rapport au sel total"
    End With
End With