In meiner Tabelle Sortiere ich abwechselnd immer mit Doppelklick auf die Zeile1.
Aber leider wird mir die erste Zeile auch sortiert
Frage:
Was muss ich im VBA Code Ändern Damit die erste Zeile nicht sortiert wird sondern immer erst ab Zeile 2.
In der ersten Zeile sind Überschriften die sollen ja nicht sortiert werden.
Danke
'Soriert bei Doppelklick auf Zeile 1 abwechselnd A-Z und Z-A
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Dim Bereich1 As Range
Dim LSpalte As Integer
Dim lzeile As Long
Dim SelectHeadline As Variant
LSpalte = ActiveSheet.UsedRange.SpecialCells(xlCellTypeLastCell).Column
lzeile = ActiveSheet.UsedRange.SpecialCells(xlCellTypeLastCell).Row
Set Bereich1 = Range(Cells(1, 1), Cells(1, LSpalte))
If Intersect(Target, Bereich1) Is Nothing Then
Exit Sub
Else
If my_sort Then
SelectHeadline = ActiveCell.Address(RowAbsolute:=False, columnAbsolute:=False)
Range(Cells(1, 1), Cells(lzeile, LSpalte)).Sort Key1:=Range(SelectHeadline), Order1:=xlAscending, Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
my_sort = False
Else
SelectHeadline = ActiveCell.Address(RowAbsolute:=False, columnAbsolute:=False)
Range(Cells(1, 1), Cells(lzeile, LSpalte)).Sort Key1:=Range(SelectHeadline), Order1:=xlDescending, Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
my_sort = True
End If
End If
Application.Calculation = xlCalculationAutomatic
Range("B2").Select
Application.ScreenUpdating = True
End Sub
GrußOraculix