Forum

How to ensure that ...
 
Notifications
Clear all

How to ensure that created macro understands the last row

2 Posts
2 Users
0 Reactions
39 Views
(@santosh)
Posts: 1
New Member
Topic starter
 

The macro that was created for formatting had 2800 rows of data. However, the new report has 8000 rows keeping columns constant. The macro is not picking all the rows. How to ensure the same.

 
Posted : 11/03/2020 1:37 pm
(@purfleet)
Posts: 412
Reputable Member
 

Probably the most useful piece of code I have learnt.

Sub FindLastRow()

Dim Lr As Long

Lr = Cells(Rows.Count, 1).End(xlUp).Row

Debug.Print Lr

Range("a1:a" & Lr).Select

End Sub

This code will check, from the bottom upwards, and find hte last used row, you can then use the variable of LR to create a range like Range("a1:a" & Lr) and do what you need to with it. the number 1 in the middle is the column number you want to check so if you need to find the last used row in column E you would put in 5 and so on.

The variable letters can be changed to whatever suits (within reason)

Purfleet

 
Posted : 11/03/2020 3:47 pm
Share: