Martin_H
Board Regular
- Joined
- Aug 26, 2020
- Messages
- 190
- Office Version
- 365
- Platform
- Windows
Hi,
I use this macro (see below) to sort the data in ascending order in the table.
My macro is assigned to the cutom MSO button.
I'd like to transfer my macro to the state which sorts the data in ascending order on the first click, sorts the data in descending order on the second click and again in ascending order on the third click, and so on.
Basically, I want to switch between ascending and descending order by using one macro (one button).
Thank you. Much appreciated.
I use this macro (see below) to sort the data in ascending order in the table.
My macro is assigned to the cutom MSO button.
I'd like to transfer my macro to the state which sorts the data in ascending order on the first click, sorts the data in descending order on the second click and again in ascending order on the third click, and so on.
Basically, I want to switch between ascending and descending order by using one macro (one button).
Thank you. Much appreciated.
VBA Code:
Public Sub Ascending_Order(ByRef control As Office.IRibbonControl)
With Application
.ScreenUpdating = False
Dim LastCell As Range
With ActiveSheet
Set LastCell = .Cells(Rows.Count, 2).End(xlUp)
.Range("D3", LastCell).sort Key1:=.Range("D3"), Order1:=xlAscending, Header:=xlYes, MatchCase:=False, Orientation:=xlTopToBottom, DataOption1:=xlSortTextAsNumbers
End With
With Range("B3").Font
.Color = vbGreen: .Bold = True
End With
With Range("U3,N3,O3,P3,Q3.F3").Font
.Color = vbWhite: .Bold = False
End With
.ScreenUpdating = True
End With
End Sub