我搜索了论坛,但我无法找到问题的确切解决方案。我对vba和编码有点熟悉,但我对VBA语法仍然很新。我一直在语法错误的时候得到错误,对象不在范围内等等。我想摆脱基于选择的操作,我想从工作表中调用特定的图表来计算其中的数据系列数量。
看起来很简单,此时我很沮丧,我还没有能够实际调试它。我已经尝试了很多不同的组合,并且整个上午一直在谷歌搜索,我得到的是新的和不同的错误消息。所以我认为你们中的一个人可能比我的修修补补更快。任何帮助都会非常有帮助,谢谢!
Dim SheetName As String
Dim SC2 As Long
SheetName = ActiveSheet.Name 'assign the name of the active sheet to the variable
'Count # of series in chart to find # of loops required
ActiveWorkbooks.Sheets(Volume CT).ChartObjects(1).Chart.SeriesCollection.Count
'*^^^THIS IS WHERE THE ERROR OCCURS*
'Debug.Print ThisWorkbook.Sheets("Time CT").ChartObjects(1).Chart.SeriesCollection.Count
'Debug.Print ThisWorkbook.Sheets("Temp CT").ChartObjects(1).Chart.SeriesCollection.Count
答案 0 :(得分:1)
Dim SC2 As Long
'chartobject method (chart is housed in a regular worksheet)
SC2 = ActiveWorkbook.Sheets("Volume CT").ChartObjects(1).Chart.SeriesCollection.Count
'if the chart is on a chart sheet:
SC2 = ActiveWorkbook.Sheets("Volume CT").SeriesCollection.Count