Interate backward using "Step"

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I want to loop backward through the cells in a sheet, but I don't know how.
My normal configuration for looping forward is as follows:

Dim rngCell As Range
Dim wrkSheet As ThisWorkbook.Sheets("DATA")

For Each rngCell In wrkSheet.Columns(1).UsedRange.Rows
....
....
Next

Can someone please show me how to convert this so that it will "step"
backward from the bottom of the sheet upward? Thanks much in advance.
 
Hi Quartz,

Try something like:


Sub sTester02()
Dim rng As Range
Dim i As Long, j As Long
Dim sh As Worksheet

Set sh = ThisWorkbook.Sheets('"DATA")

j = Cells(Rows.Count, "A").End(xlUp).Row

For i = j To 1 Step -1
'// do something,
Next i

End Sub
 

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

Back
Top