gmooney
Active Member
- Joined
- Oct 21, 2004
- Messages
- 252
- Office Version
- 365
- Platform
- Windows
Hi,
I have some code that essentially will do a re-sort of some data. Currently the data is not a table. One month the data might have 5,697 rows and the next month something like 3,154 rows.
I want to be able to have my VBA code always recognize the last row in the data that I want sorted.
Can someone give me an example of how to do this?
Here is some of my current code:
Range("A2").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
ActiveWorkbook.Worksheets("Items").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Items").Sort.SortFields.Add2 Key:=Range("F2:F5697" _
), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Items").Sort
.SetRange Range("A1:F5697")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
I have some code that essentially will do a re-sort of some data. Currently the data is not a table. One month the data might have 5,697 rows and the next month something like 3,154 rows.
I want to be able to have my VBA code always recognize the last row in the data that I want sorted.
Can someone give me an example of how to do this?
Here is some of my current code:
Range("A2").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
ActiveWorkbook.Worksheets("Items").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Items").Sort.SortFields.Add2 Key:=Range("F2:F5697" _
), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Items").Sort
.SetRange Range("A1:F5697")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With