行跳过了,但是当我通过时有效

时间:2019-03-08 16:10:53

标签: excel vba

我创建了这个宏,它跳过了这一行:

.ChartGroups(1).GapWidth = 30

如果我逐步执行宏,它将起作用。

我尝试在多个位置添加行,我尝试添加延迟。似乎什么都没用。

宏自动为每行3个输入提供条形图。

Sub CreateCharts()
    Dim cht As ChartObject
    Dim SA_Row, erow As Integer
    Dim Graph_Position As Variant

    SA_Row = 5
    Graph_Position = 79.5
    erow = Worksheets("Graphs").UsedRange.Rows.count

    For count = 5 To erow

        Select Case Cells(SA_Row, 6)

        Case Is <> ""

            Set cht = Worksheets("Graphs").ChartObjects.Add(Top:=Graph_Position, Left:=910, Width:=160, Height:=75)

            Set rng1 = Range(Cells(SA_Row, 6), Cells(SA_Row, 7))
            Set rng2 = Union(Cells(SA_Row, 8), rng1)
            cht.Chart.SetSourceData Source:=rng2

            With cht.Chart
                .HasAxis(xlValue) = False
                .HasAxis(xlCategory) = False
                .Axes(xlValue).MajorGridlines.Delete
                .HasLegend = False
                .ChartGroups(1).GapWidth = 30
                .FullSeriesCollection(1).Points(1).Format.Fill.ForeColor.RGB = RGB(0, 204, 226)
                .FullSeriesCollection(1).Points(2).Format.Fill.ForeColor.RGB = RGB(192, 0, 0)
                .FullSeriesCollection(1).Points(3).Format.Fill.ForeColor.RGB = RGB(51, 204, 51)
                .ApplyDataLabels
                .PlotArea.Height = 65
                .ChartArea.Border.LineStyle = xlNone
            End With

            SA_Row = SA_Row + 2
            Graph_Position = Graph_Position + 80

        Case Is = ""
            SA_Row = SA_Row + 2
            Graph_Position = Graph_Position + 26

    End Select

    Next count

End Sub

DoEvents无效。

由于对象/属性不支持他的方法,因此我无法添加“ .ChartGroups(1).Select”。我试图将其添加到上方和同一行。

0 个答案:

没有答案