Zeile 22 wirft den Fehler (Set wbPath2) SieheVBA Fehlermeldung: Objektvariable oder mit Blockvariable nicht gesetzt. Kann es nicht
Dieser Code eine Schleife durch jedes Arbeitsblatt in meiner Arbeitsmappe und soll, wie es Schleifen, öffnen Sie eine andere Arbeitsmappe an die Stromschleife Iteration bezogen, dann summiere eine Spalte und lege diese SUMME in meine ursprüngliche Arbeitsmappe. Ich bekomme und Objektfehler 91. Ich kratze mich seit einiger Zeit am Kopf. Wer weiß, warum diese Fehlermeldung angezeigt wird?
Private Sub PopulateData_Click()
Application.ScreenUpdating = False
Dim ws As Worksheet
Dim lastDay As Long
lastDay = Day(WorksheetFunction.EoMonth(ComboBox1.Value & Year(Date), 0))
monthNumber = Month(DateValue("01-" & ComboBox1.Value & "-1900"))
Root = "C:\myDirectory\" & Year(Date) & "\" &
monthNumber & ". " & ComboBox1.Value & " " & Year(Date) & "\"
'TOTAL CARS PER WEEK
Dim wbPath2 As Object
sourceFile = monthNumber & ". " & ComboBox1.Value & " " & Year(Date)
sourceSheet = "\[" & ws.Name & " " & monthNumber & "." & lastDay & "." &
Format(Now(), "yy") & ".csv]"
For Each ws In ThisWorkbook.Sheets
If (ws.Name <> "Master") And (ws.Name <> "Combined") Then
Set wbPath2 = Workbooks.Open(Root & ws.Name & " " & monthNumber &
"." & lastDay & "." & Format(Now(), "yy") & ".csv")
With ws
.Cells(Application.WorksheetFunction.Match("Total cars per
week", Range("A:A"), 0), 18).Formula = "=SUM('" & Root &
sourceFile & sourceSheet & ws.Name & " " & monthNumber & "." &
lastDay & "." & Format(Now(), "yy") & "'!$H:$H)"
End With
wbPath2.Close
MsgBox wbPath2
End If
Next
Application.ScreenUpdating = True
End Sub
In welcher Zeile des Codes passiert der Fehler? –
Es sagt nicht. Jsut eine Fehlermeldung Laufzeitfehler 91 Objekt oder Mit Blockvariable nicht gesetzt. Dann drücke ich Ok. keine Option zum Debuggen –
Was passiert, wenn Sie Sub im Debug-Modus durchlaufen? Setzen Sie den Cursor irgendwo in den Code und drücken Sie F8, um den Code zeilenweise auszuführen. –