0

我编写的以下代码有问题。它应该更新以前从 DL5:HX5 运行到 DL5:IU5 的图表的条目,因此循环大约有 100 张。出于某种原因,它正在逐步执行,但我似乎有语义错误。希望有人可以阐明那是什么。

有三个数字,我不确定这是在多张纸上访问数字的最佳方式(它们是彼此相同的副本,具有不同的数据。)前两个只是将时间序列扩展为附加列(例如HX 到 IU),最后一个图只是将线条颜色格式化为不同的颜色(线条被投影和实际线条片段分割。)

Dim i As Integer

For i = 31 To ActiveWorkbook.Worksheets.Count

On Error Resume Next

Worksheets(i).ChartObjects("Chart 2").Activate
ActiveChart.SeriesCollection(1).Values = "='" & Worksheets(i).Name & "'!$DL$5:$IU$5"
ActiveChart.SeriesCollection(1).XValues = "='" & Worksheets(i).Name & "'!$DL$3:$IU$3"

Worksheets(i).ChartObjects("Chart 6").Activate
ActiveChart.SeriesCollection(1).Values = "='" & Worksheets(i).Name & "'!$DL$14:$IU$14"
ActiveChart.SeriesCollection(2).Values = "='" & Worksheets(i).Name & "'!$DL$15:$IU$15"
ActiveChart.SeriesCollection(3).Values = "='" & Worksheets(i).Name & "'!$DL$16:$IU$16"
ActiveChart.SeriesCollection(3).XValues = "='" & Worksheets(i).Name & "'!$DL$3:$IU$3"

Worksheets(i).ChartObjects("Chart 1").Activate
ActiveChart.SeriesCollection(1).Points(30).Border.Color = RGB(69, 114, 167)
ActiveChart.SeriesCollection(1).Points(30).Format.Line.ForeColor.RGB = RGB(69, 114, 167)

Next i
4

1 回答 1

0

您应该避免激活/选择可以的位置。未经测试:

Sub Tester()

Dim i As Integer
Dim sht As Worksheet

    For i = 31 To ActiveWorkbook.Worksheets.Count
        Set sht = ActiveWorkbook.Sheets(i)

        With sht.ChartObjects("Chart 2").Chart.SeriesCollection(1)
            .Values = sht.Range("$DL$5:$IU$5")
            .XValues = sht.Range("$DL$3:$IU$3")
        End With

        With sht.ChartObjects("Chart 6").Chart
            .SeriesCollection(1).Values = sht.Range("$DL$14:$IU$14")
            .SeriesCollection(2).Values = sht.Range("$DL$15:$IU$15")
            .SeriesCollection(3).Values = sht.Range("$DL$16:$IU$16")
            .SeriesCollection(3).XValues = sht.Range("$DL$3:$IU$3")
        End With

        With sht.ChartObjects("Chart 1").Chart.SeriesCollection(1).Points(30)
            .Border.Color = RGB(69, 114, 167)
            .Format.Line.ForeColor.RGB = RGB(69, 114, 167)
        End With

    Next i

End Sub

编辑:重命名图表

For i = 31 To ActiveWorkbook.Worksheets.Count
        With ActiveWorkbook.Sheets(i)
            on error resume next
            .chartobjects("Chart 13").Name = "Chart 2"
            on error goto 0
        End With
Next i
于 2013-09-03T16:37:02.463 回答