ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Loop a range from bottom up (https://www.excelbanter.com/excel-programming/367996-loop-range-bottom-up.html)

Who I Am

Loop a range from bottom up
 
If I use something like

for each c in range()
next c

the loop will start from the first cell down.

How can I loop from bottom up? Here is the scenario:

1/1/2006
...
...
...
3/31/3006
3/31/2006
3/31/2006

I need the address of the last occurance of 3/31/2006, so I can count
all records from 1/1 to 3/31. If I only loop from top down, the first
occurance of 3/31 isn't want I want.

I will use the start cell address (1/1/2006) and end cell address
(3/31/2006) in another function.

Thanks in advance.


excelent

Loop a range from bottom up
 
test in kolumn A

Sub tst()
For r = 1 To 100
If Cells(r, 1) = DateSerial(2006, 1, 31) Then x = Cells(r, 1).Address
Next
MsgBox ("") & x
End Sub



"Who I Am" skrev:

If I use something like

for each c in range()
next c

the loop will start from the first cell down.

How can I loop from bottom up? Here is the scenario:

1/1/2006
...
...
...
3/31/3006
3/31/2006
3/31/2006

I need the address of the last occurance of 3/31/2006, so I can count
all records from 1/1 to 3/31. If I only loop from top down, the first
occurance of 3/31 isn't want I want.

I will use the start cell address (1/1/2006) and end cell address
(3/31/2006) in another function.

Thanks in advance.



excelent

Loop a range from bottom up
 
ups

If Cells(r, 1) = DateSerial(2006, 3, 31) Then x = Cells(r, 1).Address




"excelent" skrev:

test in kolumn A

Sub tst()
For r = 1 To 100
If Cells(r, 1) = DateSerial(2006, 1, 31) Then x = Cells(r, 1).Address
Next
MsgBox ("") & x
End Sub



"Who I Am" skrev:

If I use something like

for each c in range()
next c

the loop will start from the first cell down.

How can I loop from bottom up? Here is the scenario:

1/1/2006
...
...
...
3/31/3006
3/31/2006
3/31/2006

I need the address of the last occurance of 3/31/2006, so I can count
all records from 1/1 to 3/31. If I only loop from top down, the first
occurance of 3/31 isn't want I want.

I will use the start cell address (1/1/2006) and end cell address
(3/31/2006) in another function.

Thanks in advance.



Charlie

Loop a range from bottom up
 
For iRow = LastRow To FirstRow Step -1
Debug.Print Cells(iRow, "A")
Next iRow


"Who I Am" wrote:

If I use something like

for each c in range()
next c

the loop will start from the first cell down.

How can I loop from bottom up? Here is the scenario:

1/1/2006
...
...
...
3/31/3006
3/31/2006
3/31/2006

I need the address of the last occurance of 3/31/2006, so I can count
all records from 1/1 to 3/31. If I only loop from top down, the first
occurance of 3/31 isn't want I want.

I will use the start cell address (1/1/2006) and end cell address
(3/31/2006) in another function.

Thanks in advance.




All times are GMT +1. The time now is 07:47 AM.

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