Code to find first empty row at end of list

melodramatic

Board Regular
Joined
Apr 28, 2003
Messages
180
Office Version
  1. 365
Platform
  1. Windows
I am creating a macro that will keep up with a Master Document Log for each project, whereas my users can use the macro face to pull up the MDL, and it will auto-update.

However, the problem that I'm having is figuring out how to tell my code which row to use.

For instance, I have a project file that has 102 entries. I need to put a variable in cell A107 (the data starts at A6). But, in another project, I have only 4 entries at this time, and the data needs to go into cell A9.

What language will I use to have the macro auto-select the correct row?
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
This goes to the very last row in column A and then goes back up until the first cell it finds with data and returns the row number to the variable LR.



Code:
Dim LR As Long     'Variable for the last row number.

LR = Cells(Rows.Count, 1).End(xlUp).Row  'The 1 is for column A, change it for a different column.
 
Upvote 0
LR = Cells(Rows.Count, 1).End(xlUp).Row 'The 1 is for column A, change it for a different column
Just so you know, Cells can take a column number or column letter reference for its second argument; so, these both produce identical results...

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

LR = Cells(Rows.Count, "A").End(xlUp).Row
 
Upvote 0
Code:
sub macro()
Dim LR As Long     'Variable for the last row number.


LR = Cells(Rows.Count, 1).End(xlUp).Row  'The 1 is for column A, change it for a different column.
end

this code not selecting the last one.
 
Upvote 0

Forum statistics

Threads
1,214,788
Messages
6,121,588
Members
449,039
Latest member
Arbind kumar

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top