ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Last Active Row (https://www.excelbanter.com/excel-programming/292714-last-active-row.html)

Bill Sturdevant

Last Active Row
 
I want to loop through each row, doing verious things, and
I need to stop at the last active row. I never know
exactly how many rows are active.

What VB reference do I use to get that number:

For i = 1 to ??????
Do Stuff
next i

Ron de Bruin

Last Active Row
 
If you have data in the first row

For I = 1 To ActiveSheet.UsedRange.Rows.Count

Or if you only test data in one column

For I = 1 To ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row



--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)
www.rondebruin.nl



"Bill Sturdevant" wrote in message ...
I want to loop through each row, doing verious things, and
I need to stop at the last active row. I never know
exactly how many rows are active.

What VB reference do I use to get that number:

For i = 1 to ??????
Do Stuff
next i




Charles

Last Active Row
 
Bill try something like this.

Dim rng as Long
Set rng = Worksheets("sheet1").Cells(1,1).CurrentRegion

for i = 1 to rng.rows.count
'''' Do something '''
next i

HTH


Charle

--
Message posted from http://www.ExcelForum.com


darrelstickler

Last Active Row
 
the following works. don't know if it's elegant or not

Set dataSheet = ActiveShee
totalrows = dataSheet.UsedRange.Rows.Count


All times are GMT +1. The time now is 10:17 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com