AW: Code zu Sortieren "Button" B3-D3 funktioniert nicht
26.07.2024 00:21:02
ralf_b
Private Sub CommandButton1_Click()
Call tablesort(2, 8)
Me.Hide
Unload Me
End Sub
Private Sub CommandButton2_Click()
Call tablesort(2, 1, 4)
Me.Hide
Unload Me
End Sub
Private Sub CommandButton3_Click()
Call tablesort(1, 4)
Me.Hide
Unload Me
End Sub
Function tablesort(key1&, key2&, Optional key3& = 0)
With Worksheets("2024-2025")
With .ListObjects(1)
.Sort.SortFields.Clear
.Sort.SortFields.Add2 Key:=.ListColumns(key1).Range, _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
.Sort.SortFields.Add2 Key:=.ListColumns(key2).Range, _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
If key3 > 0 Then
.Sort.SortFields.Add2 Key:=.ListColumns(key3).Range, _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
End If
.Sort.Header = xlYes
.Sort.MatchCase = False
.Sort.Orientation = xlTopToBottom
.Sort.SortMethod = xlPinYin
.Sort.Apply
End With
.Range("A1").Select
End With
Application.ScreenUpdating = True
End Function