Johnny Thunder
Well-known Member
- Joined
- Apr 9, 2010
- Messages
- 693
- Office Version
- 2016
- Platform
- MacOS
Hello Excel friends,
I have a small project I am working on and need an addition to my macro that will sort 3 columns H:J by the last active cell in Column H. I recorded a macro of me manually doing the sort but this time around the data was only 21 lines long, on occasion it may be more or less. Here is what the Macro looks like...
Range("H4:J21").Select
ActiveWorkbook.Worksheets("Pivot").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Pivot").Sort.SortFields.Add Key:=Range("J5:J21"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Pivot").Sort
.SetRange Range("H4:J21")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
So it just says Headers are at H4:J4 so use them to sort and specifically sort by J4 which is "Adjustments1" and sort it Ascending A-Z. I can't figure out how to write it. Any help will be much appreciated. Thanks Guys!
I have a small project I am working on and need an addition to my macro that will sort 3 columns H:J by the last active cell in Column H. I recorded a macro of me manually doing the sort but this time around the data was only 21 lines long, on occasion it may be more or less. Here is what the Macro looks like...
Range("H4:J21").Select
ActiveWorkbook.Worksheets("Pivot").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Pivot").Sort.SortFields.Add Key:=Range("J5:J21"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Pivot").Sort
.SetRange Range("H4:J21")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
So it just says Headers are at H4:J4 so use them to sort and specifically sort by J4 which is "Adjustments1" and sort it Ascending A-Z. I can't figure out how to write it. Any help will be much appreciated. Thanks Guys!