habe folgende Frage. In meinem Makro lasse ich bestimmte Formeln automatisch kopieren, bis die letzte Zeile der Datentabelle erreicht ist. Anschliessend sortiere ich und lasse Teilergebnisse bilden. Da die Anzahl der Zeilen schwankt, funktioniert mein Makroteil nicht Wenn die Tabelle eine abweichende Zahl von Zeilen hat, bekomme ich einen Fehler "DAten ausserhalb des Bereiches". Ich muss also auch hier die Bildung von Teilergebnissen von der Anzahl der Zeilen unabhängig machen. Die Teilergebnisse sollen für die Spalten AC bis AG gebildet werden.
Cells.Select
ActiveWorkbook.Worksheets("Tabelle1").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Tabelle1").Sort.SortFields.Add Key:=Range( _
"F2:F905"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
ActiveWorkbook.Worksheets("Tabelle1").Sort.SortFields.Add Key:=Range( _
"A2:A905"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
ActiveWorkbook.Worksheets("Tabelle1").Sort.SortFields.Add Key:=Range( _
"N2:N905"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortTextAsNumbers
ActiveWorkbook.Worksheets("Tabelle1").Sort.SortFields.Add Key:=Range( _
"O2:O905"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortTextAsNumbers
With ActiveWorkbook.Worksheets("Tabelle1").Sort
.SetRange Range("A1:AG905")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Selection.Subtotal GroupBy:=6, Function:=xlSum, TotalList:=Array(29, 30, 31 _
, 32, 33), Replace:=True, PageBreaks:=False, SummaryBelowData:=True
Columns("AC:AF").Select
Selection.Columns.Group
ActiveWindow.LargeScroll ToRight:=-1
Range("A2").Select
End