08.01.2023, 11:42
Hallo zusammen,
ich bin dabei mir eine größere Musiksammlung zusammenzustellen. Über ein Tag-Programm, lese ich die Tags aus und exportiere diese in eine CSV-Datei.
Diese rufe ich auf und formatiere Sie. Muß einfügen, dass ich mich gerade Anfange in VBA einzuarbeiten. Da dies immer die gleichen Vorggänge sind habe ich einen Makro aufgezeichnet wie fogt:
Sub InterpretenCsvOrdnen()
'
' InterpretenCsvOrdnen Makro
' Sortiert und formatiert den Inhalt der CSV-Datei
'
'
Range("A1").Select
ActiveCell.SpecialCells(xlLastCell).Select
'Range("A49").Select
'Selection.ClearContents
Range("A1,B1,C1,D1,E1,F1,G1,H1").Select
Range("H1").Activate
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 65535
.TintAndShade = 0
.PatternTintAndShade = 0
End With
With Selection.Font
.Name = "Arial"
.Size = 16
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ThemeColor = xlThemeColorLight1
.TintAndShade = 0
.ThemeFont = xlThemeFontNone
End With
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlMedium
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlMedium
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlMedium
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlMedium
End With
Selection.Borders(xlInsideVertical).LineStyle = xlNone
Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Columns("A:A").EntireColumn.AutoFit
Columns("B:B").EntireColumn.AutoFit
Columns("C:C").EntireColumn.AutoFit
Columns("D:D").EntireColumn.AutoFit
Columns("E:E").EntireColumn.AutoFit
Columns("F:F").EntireColumn.AutoFit
Columns("G:G").EntireColumn.AutoFit
Columns("H:H").EntireColumn.AutoFit
Range("A2").Select
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
Worksheets(1).Sort.SortFields.Clear
Worksheets(1).Sort.SortFields.Add2 _
Key:=Range("A2:A49"), SortOn:=xlSortOnValues, Order:=xlAscending, _
DataOption:=xlSortNormal
Worksheets(1).Sort.SortFields.Add2 _
Key:=Range("B2:B49"), SortOn:=xlSortOnValues, Order:=xlAscending, _
DataOption:=xlSortNormal
With Worksheets(1).Sort
.SetRange Range("A1:H49")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Range("A2").Select
End Sub
Wenn nun mehr als 49 Zeilen vorhanden sind funktioniert die Sortierung nur teilweise.
Wie kann ich die Anweisung
Key:=Range("B2:B49"), SortOn:=xlSortOnValues, Order:=xlAscending, _
DataOption:=xlSortNormal
so anpassen, dass Excel den Bereich von "B2" bis zur letzten gefüllten Zellen in der Spalte markiert und nicht bei "B49" stoppt.
ich bin dabei mir eine größere Musiksammlung zusammenzustellen. Über ein Tag-Programm, lese ich die Tags aus und exportiere diese in eine CSV-Datei.
Diese rufe ich auf und formatiere Sie. Muß einfügen, dass ich mich gerade Anfange in VBA einzuarbeiten. Da dies immer die gleichen Vorggänge sind habe ich einen Makro aufgezeichnet wie fogt:
Sub InterpretenCsvOrdnen()
'
' InterpretenCsvOrdnen Makro
' Sortiert und formatiert den Inhalt der CSV-Datei
'
'
Range("A1").Select
ActiveCell.SpecialCells(xlLastCell).Select
'Range("A49").Select
'Selection.ClearContents
Range("A1,B1,C1,D1,E1,F1,G1,H1").Select
Range("H1").Activate
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 65535
.TintAndShade = 0
.PatternTintAndShade = 0
End With
With Selection.Font
.Name = "Arial"
.Size = 16
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ThemeColor = xlThemeColorLight1
.TintAndShade = 0
.ThemeFont = xlThemeFontNone
End With
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlMedium
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlMedium
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlMedium
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlMedium
End With
Selection.Borders(xlInsideVertical).LineStyle = xlNone
Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Columns("A:A").EntireColumn.AutoFit
Columns("B:B").EntireColumn.AutoFit
Columns("C:C").EntireColumn.AutoFit
Columns("D:D").EntireColumn.AutoFit
Columns("E:E").EntireColumn.AutoFit
Columns("F:F").EntireColumn.AutoFit
Columns("G:G").EntireColumn.AutoFit
Columns("H:H").EntireColumn.AutoFit
Range("A2").Select
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
Worksheets(1).Sort.SortFields.Clear
Worksheets(1).Sort.SortFields.Add2 _
Key:=Range("A2:A49"), SortOn:=xlSortOnValues, Order:=xlAscending, _
DataOption:=xlSortNormal
Worksheets(1).Sort.SortFields.Add2 _
Key:=Range("B2:B49"), SortOn:=xlSortOnValues, Order:=xlAscending, _
DataOption:=xlSortNormal
With Worksheets(1).Sort
.SetRange Range("A1:H49")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Range("A2").Select
End Sub
Wenn nun mehr als 49 Zeilen vorhanden sind funktioniert die Sortierung nur teilweise.
Wie kann ich die Anweisung
Key:=Range("B2:B49"), SortOn:=xlSortOnValues, Order:=xlAscending, _
DataOption:=xlSortNormal
so anpassen, dass Excel den Bereich von "B2" bis zur letzten gefüllten Zellen in der Spalte markiert und nicht bei "B49" stoppt.