Hi, guys.
My code is supposed to call subs that update sheets on saving. If sheets exist in the workbook, it works fine. Then I modified it to check if sheet exists and removed Sheet2 and Sheet4. Checking if Sheet2 exists with
doesn't show any error and skips to label_2:. Weird (to me) is that the same check for Sheet4 with
despite On Error GoTo shows error message: Run-time error '424'. Object required.
My code is supposed to call subs that update sheets on saving. If sheets exist in the workbook, it works fine. Then I modified it to check if sheet exists and removed Sheet2 and Sheet4. Checking if Sheet2 exists with
Code:
If Not Worksheets(Sheet2.Name) Is Nothing Then
Code:
If Not Worksheets(Sheet4.Name) Is Nothing Then
Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Application.ScreenUpdating = False
On Error GoTo label_1:
If Not Worksheets(Sheet1.Name) Is Nothing Then
Call Sheet1_Update
End If
label_1:
On Error GoTo label_2:
If Not Worksheets(Sheet2.Name) Is Nothing Then
Call Sheet2_Update
End If
label_2:
On Error GoTo label_3:
If Not Worksheets(Sheet3.Name) Is Nothing Then
Call Sheet3_Update
End If
label_3:
On Error GoTo label_4:
If Not Worksheets(Sheet4.Name) Is Nothing Then
Call Sheet4_Update
End If
label_4:
Application.ScreenUpdating = True
End Sub