How to change series name in VBA

前端 未结 2 1909
滥情空心
滥情空心 2020-12-19 11:04

I have a series of charts I am creating using VBA (code below).

I am having trouble changing the names of the series from series 1 and series 2 to Current State and

相关标签:
2条回答
  • 2020-12-19 11:33

    I believe the problem is with referencing - in the code you reference ActiveChart (I am guessing it does not exist), while you have created MAChart in the code above.

     Set Srs1 = MAChart.SeriesCollection(1) 
     Srs1.Name = "Current State"
     Set Srs2 = MAChart.SeriesCollection(2) 
     Srs2.Name = "Proposed Solution"
    
    0 讨论(0)
  • 2020-12-19 11:38

    Try changing these lines ...

         Set Srs1 = ActiveChart.SeriesCollection(1) 
         Srs1.Name = "Current State"
         Set Srs2 = ActiveChart.SeriesCollection(2) 
         Srs2.Name = "Proposed Solution"
    

    To ...

         .SeriesCollection(1).Name = "Current State"
         .SeriesCollection(2).Name = "Proposed Solution"
    

    You are already using MAChart inside your With block so you should be able to access it's .SeriesCollection(x).Name properties in the same fashion as you have done for the other properties.

    0 讨论(0)
提交回复
热议问题