End(xlDown) error if only 1 row

mdr8c

Board Regular
Joined
Feb 7, 2006
Messages
93
Hello!

I have the following code in my macro:
EndRow = Range("A16").End(xlDown).Row

I am using that code to identify the last row with data in it. For example, if I have numbers entered in cells A16, A17, and A18, the code finds the last row as row 18. However, the error occurs if I only have a number in cell A16. Even with no numbers in the subsequent rows, the EndRow command jumps to the last line of the entire spreadsheet (65536). How can I change the code so that if I only have 1 row of data, the EndRow stops at A16?

Thanks,
Margaret
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Thanks! That worked great. Now can you please explain to me why it worked?
I presume that "Rows.Count" counts how many rows have numbers in them, but then how does End(xlUp) make it find the bottom row?
 
Upvote 0
It basically finds ("A" & Rows.Count) which is A65536 in Excel prior to XL 2007, then looks back up to the last filled row.
 
Upvote 0

Forum statistics

Threads
1,214,583
Messages
6,120,383
Members
448,955
Latest member
BatCoder

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