AT_TreeFortConsulting
New Member
- Joined
- Aug 3, 2021
- Messages
- 14
- Office Version
- 2016
- Platform
- Windows
Hi all -
I recorded a macro to sort a table by oldest to newest date using a button, and would like to have it sort by newest to oldest if I click the button a second time, but don't know how to get to the second part. Below is what I recorded to sort oldest to newest:
' sort_by_date Macro
'
'
ActiveWorkbook.Worksheets("Daily Activity").ListObjects("tbl_daily_tracker"). _
Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Daily Activity").ListObjects("tbl_daily_tracker"). _
Sort.SortFields.Add2 Key:=Range("tbl_daily_tracker[Date]"), SortOn:= _
xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("Daily Activity").ListObjects("tbl_daily_tracker"). _
Sort.SortFields.Add2 Key:=Range("tbl_daily_tracker[Activity]"), SortOn:= _
xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Daily Activity").ListObjects( _
"tbl_daily_tracker").Sort
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
I recorded a macro to sort a table by oldest to newest date using a button, and would like to have it sort by newest to oldest if I click the button a second time, but don't know how to get to the second part. Below is what I recorded to sort oldest to newest:
' sort_by_date Macro
'
'
ActiveWorkbook.Worksheets("Daily Activity").ListObjects("tbl_daily_tracker"). _
Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Daily Activity").ListObjects("tbl_daily_tracker"). _
Sort.SortFields.Add2 Key:=Range("tbl_daily_tracker[Date]"), SortOn:= _
xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("Daily Activity").ListObjects("tbl_daily_tracker"). _
Sort.SortFields.Add2 Key:=Range("tbl_daily_tracker[Activity]"), SortOn:= _
xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Daily Activity").ListObjects( _
"tbl_daily_tracker").Sort
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub