End Up vs. CurrentRegion.Rows Count

Todd Bardoni

Well-known Member
Joined
Aug 29, 2002
Messages
3,042
What is everyone's opinion on the following. Often, I have to loop through large amounts of data inserting, say, formulas to the last row. I'm trying to figure what is overall best to use. I've been using something such as the following:

MyRegion=Sheet1.Cells.CurrentRegion.Rows
MyRows=MyRegion.Count

But, now I'm thinking for numerous reasons that this isn't so good. It might not select the entire range due to blank rows or columns, I think its kind of slow, etc.

Would it be better to use:

For Each ThisCell2 In ActiveSheet.Range("F1:F" & Range("F65536").End(xlUp).Row) (courtesy of phantom1975)

Just wondering.
 
Hi Yogi, one note of caution !!

You wrote:
"then going up from cell F65536 to the first occupied cell that is encountered is indeed foolproof."

Versions of Excel before 97 (Excel5 / Excel95, for instance, which is still in use by some) only have 16,384 rows in their worksheets, so the reference to 65,536 would return an error. And who knows, Microsoft might wake up and offer future versions with more than 65,536 rows (not rumored for the upcoming release of Office 2003 this summer unfortunately).

So, the more "foolproof" method would be (for column F in this example):
Cells(Rows.Count, 6).End(xlUp)
 
Upvote 0

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
How is it the best spreadsheet software in the world has some of the biggest downfalls (ie, 65,536 rows?) And how come Microsoft doesn't correct this? All that money and they can't fix this? Must be laziness...

Anyway, enough spouting off. Thanks for the input, Tom.
 
Upvote 0
So, the more "foolproof" method would be (for column F in this example):
Cells(Rows.Count, 6).End(xlUp)

Good point Tom -- I have seen you use this in some other posts as well. Thank You!
 
Upvote 0

Forum statistics

Threads
1,214,907
Messages
6,122,183
Members
449,071
Latest member
cdnMech

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