Hi,
(12.09.2017, 22:33)Wodan schrieb: [ -> ]Das Makro darf sich also nicht nur auf das Tabellenblatt "Sägeliste Fräsen" beziehen, sondern auch auf das andere Blatt "Sägeliste Drehen", oder muss ganz allgemein gehalten sein. Nur wie erstelle ich ein allgemeingültiges Makro?
dann weise doch den Sheet-Namen einer Variablen zu und verwende die Variable entsprechend:
Option Explicit
Sub FräsenNormal()
'
' FräsenNormal Makro
'
Dim strBlatt As String
'
strBlatt = ActiveWorkbook.ActiveSheet.Name
Cells.Select
Range("G11").Activate
With ActiveWorkbook.Worksheets(strBlatt)
.Sort.SortFields.Clear
.Sort.SortFields.Add Key:=Range("U2:U3681"), SortOn:=xlSortOnValues, _
Order:=xlAscending, DataOption:=xlSortNormal
.Sort.SortFields.Add Key:=Range("C2:C3681"), SortOn:=xlSortOnValues, _
Order:=xlAscending, DataOption:=xlSortNormal
.Sort.SortFields.Add Key:=Range("N2:N3681"), SortOn:=xlSortOnValues, _
Order:=xlAscending, DataOption:=xlSortNormal
.Sort.SortFields.Add Key:=Range("O2:O3681"), SortOn:=xlSortOnValues, _
Order:=xlAscending, DataOption:=xlSortTextAsNumbers
.Sort.SortFields.Add Key:=Range("P2:P3681"), SortOn:=xlSortOnValues, _
Order:=xlAscending, DataOption:=xlSortNormal
.Sort.SortFields.Add Key:=Range("Q2:Q3681"), SortOn:=xlSortOnValues, _
Order:=xlAscending, DataOption:=xlSortNormal
.Sort.SortFields.Add Key:=Range("R2:R3681"), SortOn:=xlSortOnValues, _
Order:=xlAscending, DataOption:=xlSortNormal
.Sort.SortFields.Add Key:=Range("S2:S3681"), SortOn:=xlSortOnValues, _
Order:=xlAscending, DataOption:=xlSortNormal
With .Sort
.SetRange Range("A1:IX3681")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End With
Range("A2").Select
End Sub
oder verwende gleich das ActiveSheet:
Option Explicit
Sub FräsenNormal()
'
' FräsenNormal Makro
'
'
Cells.Select
Range("G11").Activate
With ActiveWorkbook.ActiveSheet
.Sort.SortFields.Clear
.Sort.SortFields.Add Key:=Range("U2:U3681"), SortOn:=xlSortOnValues, _
Order:=xlAscending, DataOption:=xlSortNormal
.Sort.SortFields.Add Key:=Range("C2:C3681"), SortOn:=xlSortOnValues, _
Order:=xlAscending, DataOption:=xlSortNormal
.Sort.SortFields.Add Key:=Range("N2:N3681"), SortOn:=xlSortOnValues, _
Order:=xlAscending, DataOption:=xlSortNormal
.Sort.SortFields.Add Key:=Range("O2:O3681"), SortOn:=xlSortOnValues, _
Order:=xlAscending, DataOption:=xlSortTextAsNumbers
.Sort.SortFields.Add Key:=Range("P2:P3681"), SortOn:=xlSortOnValues, _
Order:=xlAscending, DataOption:=xlSortNormal
.Sort.SortFields.Add Key:=Range("Q2:Q3681"), SortOn:=xlSortOnValues, _
Order:=xlAscending, DataOption:=xlSortNormal
.Sort.SortFields.Add Key:=Range("R2:R3681"), SortOn:=xlSortOnValues, _
Order:=xlAscending, DataOption:=xlSortNormal
.Sort.SortFields.Add Key:=Range("S2:S3681"), SortOn:=xlSortOnValues, _
Order:=xlAscending, DataOption:=xlSortNormal
With .Sort
.SetRange Range("A1:IX3681")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End With
Range("A2").Select
End Sub