Laufzeitfehler '1004' NUR bei UNgeöffnetem Sheet
Tommy
ich bekomme bei meinem Makro immer den Laufzeitfehler 1004 - Die Select-Methode des Range-Objekts konnte nicht ausgeführt werden.
Die Fehlermeldung kommt aber nur, wenn das Tabellenblatt "ManuelleListe" nicht geöffnet. Ansonsten klappt es.
Ich kann mir das nicht erklären.
Als Fehlerzeile wird myRange.Select markiert.
Das myRange habe ich nur eingeführt, weil ich im internet gelesen habe, dass sich mannchmal dieser Fehler damit beheben lässt.
Habe den Code auch schon in eine neue "frische" Arbeitsmappe kopiert. Gleiches Problem. Das heißt, wenn ihr den Code kopiert und ein Tabellenblatt mit dem Namen "ManuelleListe" erstellt, könnt ihr den Code testen.
Der komplette Code ist wie folgt:
Public Sub AbbildenLagerlayout()
Dim intExAnzGang As Integer ' Anzahl Gänge
Dim intExAnzPalGang As Integer ' Anzahl Paletten pro Gang
intExAnzGang = 10
intExAnzPalGang = 20
'With ThisWorkbook.Worksheets("Parameter") ' liest die WErte aus dem excel sheet ein
' intExAnzGang = .Range("I7").Value
' intExAnzPalGang = .Range("I8").Value
'End With
Dim RunGang As Integer
Dim RunPal As Integer
Dim wks As Worksheet
Set wks = ThisWorkbook.Worksheets("ManuelleListe")
ThisWorkbook.Worksheets("ManuelleListe").Range("B3:ZZ3").ClearContents
ThisWorkbook.Worksheets("ManuelleListe").Range("B4:ZZ1000").Clear
Dim myRange As Range
With Application
.ScreenUpdating = False
.Calculation = xlCalculationManual
.EnableEvents = False
End With
For RunPal = 1 To intExAnzPalGang
wks.Cells(3 + RunPal, 1).Value = RunPal
Next RunPal
For RunGang = 1 To intExAnzGang
wks.Cells(3, RunGang * 2).Value = RunGang
Set myRange = wks.Range(wks.Cells(4, RunGang * 2), wks.Cells(3 + intExAnzPalGang, RunGang * _
_
2))
myRange.Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlMedium
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlMedium
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlMedium
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlMedium
End With
Selection.Borders(xlInsideVertical).LineStyle = xlNone
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlMedium
End With
Next
ThisWorkbook.Worksheets("ManuelleListe").Rows(4 & ":" & (4 + intExAnzPalGang)).Select
Selection.RowHeight = 40
ThisWorkbook.Worksheets("ManuelleListe").Range(Columns(2), Columns(2 + intExAnzGang * 2)). _
_
Select
Selection.ColumnWidth = 4
With Application
.ScreenUpdating = True
.Calculation = xlCalculationAutomatic
.EnableEvents = True
End With
End Sub
Ich weiß leider einfach nicht merh weiter. Wenn du mir hier helfen kansnt, wäre ich dir serh dankbar!
Grüße
Tommy