Hello amazing Excel users,
Rox here, an excel novice, but great admirer of all it can do...
I recorded two simple macros to filter columns in a specific order. I'd love to clean up the VBA code AND update it, so the macro can work on another sheet with a different name. (Confirming these new sheets will always be in the same column order and the row the filter will be on, will be the same).
I'm hoping someone can help me replace the specific Sheet name (in red below) with a variable, so it works on any active sheet in the future?
Desired VBA code 'outcomes':
1. Clear all filters
2. Sort by Column A, in ascending order
Current code looks as follows:
(Note - I first added a random filter, to then 'Clear all', because when I tried to start with 'Clear all' I either got an error message, or it didn't clear the filter that I manually added )
I have a second Macro, which is a bit more involved - but hopefully if someone can steer me in the right direction on this one, I can have a crack at the second one, myself.
Thank you in advance for any help
Rox
Rox here, an excel novice, but great admirer of all it can do...
I recorded two simple macros to filter columns in a specific order. I'd love to clean up the VBA code AND update it, so the macro can work on another sheet with a different name. (Confirming these new sheets will always be in the same column order and the row the filter will be on, will be the same).
I'm hoping someone can help me replace the specific Sheet name (in red below) with a variable, so it works on any active sheet in the future?
Desired VBA code 'outcomes':
1. Clear all filters
2. Sort by Column A, in ascending order
Current code looks as follows:
(Note - I first added a random filter, to then 'Clear all', because when I tried to start with 'Clear all' I either got an error message, or it didn't clear the filter that I manually added )
Code:
ActiveSheet.Range("$A$4:$AX$141").AutoFilter Field:=9, Criteria1:="Adapt"
ActiveSheet.ShowAllData
ActiveWorkbook.Worksheets("Q2_2022 WIP").AutoFilter.Sort.SortFields _
.Clear
ActiveWorkbook.Worksheets("Q2_2022 WIP").AutoFilter.Sort.SortFields _
.Add2 Key:=Range("A4:A141"), SortOn:=xlSortOnValues, Order:=xlAscending, _
DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Q2_2022 WIP").AutoFilter.Sort
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
I have a second Macro, which is a bit more involved - but hopefully if someone can steer me in the right direction on this one, I can have a crack at the second one, myself.
Thank you in advance for any help
Rox