By using the following VBA code, you can drop it in a double-click event on a worksheet to get to the column header of the worksheet (double-click the name of the column), and the current column is sorted automatically.
For example, place your code in the following event:
Private Sub Worksheet_selectionchange (ByVal Target as Range)
End Sub
The code is as follows:
Dim Yourg as Range
If target.column <= me.cells (1,1). CurrentRegion.Columns.Count and Target.Row = 1 Then
If target.column <> Mncolumn Then
Mncolumn = Target.Column
Mndirection = xlascending
Else
If mndirection = xlascending Then
Mndirection = xldescending
Else
Mndirection = xlascending
End If
End If
Set Yourg = me.cells (1, 1). CurrentRegion
Yourg. Sort Key1:=yourg. Cells (1, mncolumn), Order1:=mndirection,header:=xlyes
Set Yourg = Nothing
Cancel = True
End If
The above code is sorted in ascending order, and you can sort by descending order.