-3

我目前正在使用这个宏来生成我从另一张纸中获取价值的图表。当未检测到 sheet1 在 A 列中没有任何输入时,如何通过停止添加系列来简化这一点。

        ActiveSheet.ChartObjects("CH 1").Activate
        ActiveChart.SeriesCollection.NewSeries.MarkerStyle = False
        ActiveChart.SeriesCollection(1).Name = "='Sheet1'!$A$2"
        ActiveChart.SeriesCollection(1).Values = "='data'!$B$2:$B$400"
        ActiveChart.SeriesCollection.NewSeries
        ActiveChart.SeriesCollection(2).Name = "='Sheet1'!$A$3"
        ActiveChart.SeriesCollection(2).Values = "='data (2)'!$B$2:$B$400"
        ActiveChart.SeriesCollection.NewSeries
        ActiveChart.SeriesCollection(3).Name = "='Sheet1'!$A$4"
        ActiveChart.SeriesCollection(3).Values = "='data (3)'!$B$2:$B$400"
        ActiveChart.SeriesCollection.NewSeries
        ActiveChart.SeriesCollection(4).Name = "='Sheet1'!$A$5"
        ActiveChart.SeriesCollection(4).Values = "='data (4)'!$B$2:$B$400"
        ActiveChart.SeriesCollection.NewSeries
        ActiveChart.SeriesCollection(5).Name = "='Sheet1'!$A$6"
        ActiveChart.SeriesCollection(5).Values = "='data (5)'!$B$2:$B$400"
        ActiveChart.SeriesCollection.NewSeries
        ActiveChart.SeriesCollection(6).Name = "='Sheet1'!$A$7"
        ActiveChart.SeriesCollection(6).Values = "='data (6)'!$B$2:$B$400"
        ActiveChart.SeriesCollection.NewSeries
        ActiveChart.SeriesCollection(7).Name = "='Sheet1'!$A$8"
        ActiveChart.SeriesCollection(7).Values = "='data (7)'!$B$2:$B$400"
        ActiveChart.SeriesCollection.NewSeries
        ActiveChart.SeriesCollection(8).Name = "='Sheet1'!$A$9"
        ActiveChart.SeriesCollection(8).Values = "='data (8)'!$B$2:$B$400"
        ActiveChart.SeriesCollection.NewSeries
        ActiveChart.SeriesCollection(9).Name = "='Sheet1'!$A$10"
        ActiveChart.SeriesCollection(9).Values = "='data (9)'!$B$2:$B$400"
        ActiveChart.SeriesCollection.NewSeries
        ActiveChart.SeriesCollection(10).Name = "='Sheet1'!$A$11"
        ActiveChart.SeriesCollection(10).Values = "='data (10)'!$B$2:$B$400"
4

2 回答 2

1

尝试这样的事情。你的问题有点不连贯,所以如果我误解了你的意思,请发表评论。

Dim wks as Worksheet
Set wks = Sheets("Sheet1")

If WorksheetFunction.Count(wks.Columns(1)) <> 0 Then

    'insert your code here

End If
于 2013-01-03T19:45:59.290 回答
0

如果您注意到我重复此(见下文)行以在我的图表中添加更多值/系列。我如何在那里与您的代码集成。

    ActiveChart.SeriesCollection(1).Name = "='Sheet1'!$A$2"
    ActiveChart.SeriesCollection(1).Values = "='data'!$B$2:$B$400"
    ActiveChart.SeriesCollection.NewSeries
    ActiveChart.SeriesCollection(2).Name = "='Sheet1'!$A$3"
    ActiveChart.SeriesCollection(2).Values = "='data (2)'!$B$2:$B$400"
于 2013-01-04T00:32:59.717 回答