Tobi
Tobi

Reputation: 89

Excel VBA - move chart series to the end of the table

I need help with the below code:

ThisWorkbook.Worksheets("Overall Performance").Activate
ActiveSheet.ChartObjects("Chart 2").Activate
ActiveChart.SetSourceData Source:=Range("$B$8:$BI$11")

My table is as follows:

I tried to modify code to ActiveChart.SetSourceData Source:=Range("$B$8:$BI$11" & LastRow) buy it doesn't do anything.

How to modify this code to automatically select all the missing data in my table? Thanks

enter image description here

Upvotes: 1

Views: 298

Answers (2)

Tobi
Tobi

Reputation: 89

Good news, I managed to find a solution to my query by using the CurrentRegion property (thanks Pᴇʜ for improving my code). Hope this helps everyone facing the same problem.

ThisWorkbook.Worksheets("Overall Performance").Activate
ActiveSheet.ChartObjects("Chart 2").Activate
ActiveChart.SetSourceData Source:=Range("$B$8:$BI$11").CurrentRegion

Upvotes: 1

DisplayName
DisplayName

Reputation: 13386

Use

ActiveChart.SetSourceData Source:=Range("$B$8:$BI$" & LastRow)

Where I assume LastRow holds the row index of the last relevant row

You can set LastRow as follows:

LastRow = Cells(Rows.Count, 2).End(xlup).Row

Upvotes: 0

Related Questions