Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 42225

MsOf07 [RESOLVED] Check for worksheet's name generates Run-time Error 424

$
0
0
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
Code:

If Not Worksheets(Sheet2.Name) Is Nothing Then

doesn't show any error and skips to label_2:. Weird (to me) is that the same check for Sheet4 with
Code:

If Not Worksheets(Sheet4.Name) Is Nothing Then

despite On Error GoTo shows error message: Run-time error '424'. Object required.
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


Viewing all articles
Browse latest Browse all 42225

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>