Reputation: 89
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
Upvotes: 1
Views: 298
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
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