Excel_User_10k
Board Regular
- Joined
- Jun 25, 2022
- Messages
- 100
- Office Version
- 2021
- Platform
- Windows
Hi, here is an easy one for you...but still beyond me unfortunately.
I have recorded a macro to sort a sheet of dynamic data and I have one for each month.
It does what I need it to but the recorded code is specific to the worksheet I recorded it on. I know I don't need to duplicate this code for every single monthly worksheet and there should just be an "active.worksheet" code in there somewhere instead. But I do not know how to make this adjustment after several failed attempts.
I would like to just be able to assign the same code to every button created for each monthly worksheet and it only run on the sheet that it is clicked.
Thank You.
This is the code as it stands:
Exactly the same scenario with this code too please.
I have recorded a macro to sort a sheet of dynamic data and I have one for each month.
It does what I need it to but the recorded code is specific to the worksheet I recorded it on. I know I don't need to duplicate this code for every single monthly worksheet and there should just be an "active.worksheet" code in there somewhere instead. But I do not know how to make this adjustment after several failed attempts.
I would like to just be able to assign the same code to every button created for each monthly worksheet and it only run on the sheet that it is clicked.
Thank You.
This is the code as it stands:
VBA Code:
Sub Sort_Adviser()
'
' Sort_Adviser Macro
'
'
ActiveWorkbook.Worksheets("April").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("April").Sort.SortFields.Add2 Key:=Range("P13:P45") _
, SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("April").Sort.SortFields.Add2 Key:=Range("E13:E45") _
, SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("April").Sort
.SetRange Range("B13:S45")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
Exactly the same scenario with this code too please.
VBA Code:
Sub Sort_Store()
'
' Sort_Store Macro
'
'
ActiveWorkbook.Worksheets("April").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("April").Sort.SortFields.Add2 Key:=Range("P2:P6"), _
SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("April").Sort.SortFields.Add2 Key:=Range("E2:E6") _
, SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("April").Sort
.SetRange Range("D2:S6")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Range("O9").Select
End Sub