Sometimes, You may need to find and select the first blank cell or last blank cell in a column, these macros can help you.
Find and Select the First Blank Cell in Column A
or
First blank cell: before selection
First blank cell: after selection
Find and Select the Last Blank Cell in Column A
or
Note: Some of the most common ways of finding last row which are highly unreliable and hence should never be used:
UsedRange
xlDown
CountA
Why we use Rows.Count not 65536?
This question is a classic scenario where the code will fail because the Rows.Count
returns 65536
for Excel 2003 and earlier and 1048576
for Excel 2007 and later. The above fact that Excel 2007+ has 1048576
rows also emphasizes on the fact that we should always declare the variable which will hold the row value as Long
instead of Integer
else you will get an Overflow
error.
How to use it
To use this macro, you can copy and paste it into a standard module:
- Activate the Visual Basic Editor by pressing ALT F11.
- Right-click the project/workbook name in the Project window.
- Choose Insert -> Module.
- Type or paste the code in the newly created module.
Hi all,
I don't know if this has been covered.
I have a named range (Calen) that is A1 to L22.
When I copy from another sheet, I would like to find and paste in the first empty cell.
In the order of top to bottom then left to right.
So I would need C1 through C22 before moving to F1 through F22, etc.
Just substitute Columns("F") instead of Columns(1)