firstlastrow

JasonLeVan

Board Regular
Joined
Feb 7, 2011
Messages
121
I need a macro that will search column c for the first empty row and then just stay there.
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Code:
Option Explicit
Sub LastInC()
Dim finalrow As Integer
Sheet1.Activate
finalrow = Cells(Rows.Count, 3).End(xlUp).Row
Cells(finalrow + 1, 3).Select
End Sub
 
Upvote 0
This will work on the active sheet not just sheet 1


Code:
Option Explicit
Sub LastInC()
Dim finalrow As Integer
With ActiveSheet
finalrow = Cells(Rows.Count, 3).End(xlUp).Row
Cells(finalrow + 1, 3).Select
End Sub
 
Upvote 0
The only problem with that is it will select the row below the last line of data, which if there are gaps in column C may not be the first empty row.

Code:
Cells(1, 3).End(xlDown).select
could be more appropriate in this instance.

Unless there are empty cells above your headers, in which case, replace the 1 with the row number of the header row.

HTH

PS it's best not to use integer variables to store row numbers, as the integer type only goes up to 32,768. Use Double instead.

PPS

Code:
finalrow = Cells(Rows.Count, 3).End(xlUp).Row
Cells(finalrow + 1, 3).Select
can be replaced with
Code:
Cells(Rows.Count, 3).End(xlUp).offset(1).Select
in which case you don't need a variable at all
 
Upvote 0
Thanks for the tips Weaver,

I learnt 3 things there

the integer point, using offset to save a line of code and of course to read the question properly.
 
Upvote 0
After all that lecturing, I missed out the offset from my solution!

It should be:

Code:
Cells(1, 3).End(xlDown).offset(1).select
otherwise the selection is the row above the blank cell.
 
Upvote 0

Forum statistics

Threads
1,224,590
Messages
6,179,758
Members
452,940
Latest member
rootytrip

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