C
cubbybear3
I am retrieving a table from a webpage and the data is sorted in
reverse order (by date). It is a dynamic range but I compute the last
row of the range before processing. I am currently resorting the data
so I can process it by date (ascending). My question is how can
modify my current code to read from the bottom of the range to the top
(to eliminate the need for the sort)? Thanks for any ideas/
suggestions. -pb
Dim lngLast As Long
Dim rngCell As Range
' find the last row
lngLast = Sheets("Sheet1").Cells(Rows.Count, "A").End(xlUp).Row
If (lngLast < 4) Then ' first row (if data exists) is always in row
4
Exit Sub
End If
' sort the WebData
Range("A4:E" & lngLast).Select
Selection.Sort _
Key1:=Range("A4"), _
Order1:=xlAscending, _
Header:=xlNo, _
OrderCustom:=1, _
MatchCase:=False, _
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
' Loop through the WebData
For Each rngCell In Worksheets("Sheet1").Range("A4:A" & lngLast)
' process table here
Next
reverse order (by date). It is a dynamic range but I compute the last
row of the range before processing. I am currently resorting the data
so I can process it by date (ascending). My question is how can
modify my current code to read from the bottom of the range to the top
(to eliminate the need for the sort)? Thanks for any ideas/
suggestions. -pb
Dim lngLast As Long
Dim rngCell As Range
' find the last row
lngLast = Sheets("Sheet1").Cells(Rows.Count, "A").End(xlUp).Row
If (lngLast < 4) Then ' first row (if data exists) is always in row
4
Exit Sub
End If
' sort the WebData
Range("A4:E" & lngLast).Select
Selection.Sort _
Key1:=Range("A4"), _
Order1:=xlAscending, _
Header:=xlNo, _
OrderCustom:=1, _
MatchCase:=False, _
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
' Loop through the WebData
For Each rngCell In Worksheets("Sheet1").Range("A4:A" & lngLast)
' process table here
Next