(Solved) – VBA: Variable for finding last row stays at first row


Hello there First post!

-So basically I have this project for updating charts based on a set of data.
For that I need to find the last row, which works very well with this code:

'Chart for PMI

Sheets("Leading Indicators").Select



ActiveChart.SetSourceData Source:=Sheets("Leading Data").range("A2:B872"), PlotBy:=xlColumns

' imagine the next line being bold    
finalrow = Sheets("Leading Data").Cells(Sheets("Leading Data").UsedRange.Rows.Count, 1).End(xlUp).Row**

ActiveChart.SetSourceData Source:=Sheets("Leading Data").range("A2:B" & finalrow), PlotBy:=xlColumns

finalrow = 0

-Now I want to implement the same code for another sheet and it runs well BUT! last row won’t go until the actual last row and I can’t find the reason for it.. any suggestions?? Thanks in advance!

'Chart Initial

Sheets("Employment Graphs").Select



ActiveChart.SetSourceData Source:=Sheets("Employment Data").range("A2:B2780"), _

' imagine the next line being bold    
finalrow2 = Sheets("Employment Data").Cells(Sheets("Employment Data").UsedRange.Rows.Count, 1).End(xlUp).Row

ActiveChart.SetSourceData Source:=Sheets("Employment Data").range("A2:B" & finalrow2), PlotBy:=xlColumns

finalrow2 = 0  

Leave a Reply

Your email address will not be published. Required fields are marked *