Unverständlicher Laufzeitfehler 1004
27.12.2018 20:30:30
Bernd
ich bin neu in der Programmierung mit VBA. Ich habe ein Makro welches eine Arbeitsmappe durchgeht und kleinere Formatierungen vornimmt. Hier der Code:
Option Explicit
Sub Formatierung()
Dim WS_Count As Long
Dim i As Long
WS_Count = ActiveWorkbook.Worksheets.Count
' Begin the loop.
For i = 1 To WS_Count
Dim lastrow As Long
Dim lastcolumn As Long
lastrow = Worksheets(i).Cells(Rows.Count, 1).End(xlUp).Row
lastcolumn = Worksheets(i).Cells(2, Columns.Count).End(xlToLeft).Column
With Worksheets(i).PageSetup
.Orientation = xlLandscape
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = 1
End With
With Worksheets(i).Rows(2)
.Orientation = 65
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.RowHeight = 100
End With
With Worksheets(i).Range(Cells(2, 1), Cells(2, lastcolumn)).Borders
.LineStyle = xlContinuous
.Color = RGB(218, 225, 244)
End With
With Worksheets(i).Range(Cells(1, 1), Cells(1, lastcolumn))
.Merge
.Font.Bold = True
.Font.Color = RGB(94, 80, 150)
.WrapText = True
.EntireRow.AutoFit
End With
With Worksheets(i).Range(Cells(lastrow, 1), Cells(lastrow, lastcolumn))
.Merge
.Font.Bold = True
.Font.Color = RGB(94, 80, 150)
.WrapText = True
.EntireRow.AutoFit
End With
Next i
End Sub
Mein Problem taucht immer bei den With Befehlen auf die einen bestimmten Bereich bearbeiten. Also z.B. With Worksheets(i).Range(Cells(2, 1), Cells(2, lastcolumn)).BordersHier kommt immer bei einem anderen Arbeitsblatt der Laufzeitfehler 1004.
Wie gesagt bin ich neu in VBA aber auf manchen Blättern funktionierts und auf anderen nicht aber nicht immer an der selben Stelle.
Wäre super wenn mir hier wer helfen könnte.
Danke
Bernd