Reverse Direction of For-Each-Next?

F

FuzzyDove

Hi All -
part of the code I'm working on has something like:
' _______________________________
For Each XYZ In Range (Cells(topaddressrow, topaddresscolumn)
Cells(bottomaddressrow, bottomaddresscolumn))

My_Var = bla.....gather, sum, combine etc what I'm getting.... bla.

Next

Range("X5").Value = My_Var
' _______________________________

The contents of My_Var is always the result of the code working fro
the top of the range downward to the bottom of the range. It does no
matter which way I define the range.
My question is: Is there a way to make the For Each statemen
work/return data from the bottom up?

Thanks for any help!
FuzzyDov
 
H

Harald Staff

For ranges it can be done like this:

Sub test()
Dim ABC As Range
Dim XYZ As Range
Dim L As Long
Set ABC = Range(Cells(1, 1), Cells(3, 3))
For L = ABC.Count To 1 Step -1
Set XYZ = ABC(L)
MsgBox XYZ.Address
Next
End Sub

HTH. Best wishes Harald
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top