0

I am trying to create a line graph on VBA.

I have the following code:

Dim x as Range
Dim cli as Range
Dim dis as Range

Sheets("AF").Select

Range("C2").Select
Set x = Application.Range(Selection, Selection.End(xlToRight))

Range("C3").Select
Set cli = Application.Range(Selection, Selection.End(xlToRight))

Range("C4").Select
Set dis = Application.Range(Selection, Selection.End(xlToRight))

Sheets("PAPM").Select

ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.FullseriesCollection(1).Select

ActiveChart.FullseriesCollection(1).Values = cli
ActiveChart.FullseriesCollection(2).Values = dis

However the issue is that it is only plotting the line "cli" since it has data from C2 to Z2, and it is not plotting "dis" since that data starts from E2 to Z2. In the code if I start "dis" from E2 then the graphs are not on comparable months which is the x axis.

Please help me to select the range that from C2 which has no values as well.

John Coleman
  • 51,337
  • 7
  • 54
  • 119
Esmie
  • 11
  • 1
  • You might benefit from reading [How to avoid using Select in Excel VBA](https://stackoverflow.com/q/10714251/4996248). – John Coleman Oct 10 '21 at 14:31
  • "not plotting "dis" since that data starts from E2" ? dis is row 4 so do you mean it starts from E4 ? – CDP1802 Oct 10 '21 at 16:13
  • Maybe you should show us your data - otherwise it is hard to spot a potential error due to wrong referencing – Ike Oct 12 '21 at 06:16

0 Answers0