Loop from left to the right
"rumkus" wrote:
With Worksheets("sheetA")
Set rng = .Range("a2", .Range("a" & Rows.Count).End(xlUp))
For Each X In rng
'
Next X
End With
With above code i can loop through all rows of my data in column(A).
Say my data consists of unknown numbers of rows and columns and i want
to loop from last cell of column(A) to the right most column which is
unkown. I mean from left most to the right most column of last row with
data. How can i modify above code for that purpose ?
I'd do it like this:
'find the bottom of A:
ro = Cells(Cells.SpecialCells(xlCellTypeLastCell).Row, 1).End(xlUp).Row
'step through all cells in that row:
For col = 1 To Cells.SpecialCells(xlCellTypeLastCell).Column
Debug.Print Cells(ro, col).Value
Next
Adjust as you see fit.
--
- We have to compromise!
- No. Not even in the face of Armageddon. Never compromise.
|