Does anyone know how to make this work?
This error would happen if the variable ShtName was empty, or did not contain a valid sheet name. I am trying to create a custom error message for this exact error. There is a possibility of getting the runtime error in other locations in the code. So I cant just use any runtime errors.
Thank you all!
Code:
Sub Test1 ()
Dim ShtName As String
Dim ShtError As String
If IsError(Sheets(ShtName).Copy) = True Then
ShtError = ShtName & " cannot be copied due to it not existing"
GoTo Quit2:
Else
Sheets(ShtName).Copy
MsgBox(Shtname & " successfully copied")
GoTo Quit:
End IF
Quit2:
Msgbox(ShtError)
Quit:
End Sub
This error would happen if the variable ShtName was empty, or did not contain a valid sheet name. I am trying to create a custom error message for this exact error. There is a possibility of getting the runtime error in other locations in the code. So I cant just use any runtime errors.
Thank you all!