Code to find first empty row at end of list

melodramatic

Board Regular
Joined
Apr 28, 2003
Messages
170
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

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop

skywriter

Well-known Member
Joined
Feb 15, 2014
Messages
1,642
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

Rick Rothstein

MrExcel MVP
Joined
Apr 18, 2011
Messages
38,150
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
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

secoo140

Board Regular
Joined
Oct 12, 2013
Messages
85
Office Version
  1. 2010
Platform
  1. Windows
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,190,944
Messages
5,983,793
Members
439,858
Latest member
Sarrah91

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
Top