ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Interate backward using "Step" (https://www.excelbanter.com/excel-programming/320774-interate-backward-using-step.html)

quartz[_2_]

Interate backward using "Step"
 
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.

Norman Jones

Interate backward using "Step"
 
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

---
Regards,
Norman



"quartz" wrote in message
...
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.





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

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