Greetings,
My situation is this, i want to have different error messages for an error that has the same error number. pls help
thanks
Sub CopyTemp()
Dim WWcellname As String
Dim Pcellname As String
Dim Tcellname As String
Dim Workshets As String
Dim Workshets1 As String
WWcellname = Range("B1").Value
Pcellname = Range("B2").Value
Tcellname = Range("B3").Value
On Error GoTo err1
Sheets(Tcellname).Select
Sheets(Tcellname).Copy Before:=Sheets(Pcellname)
Sheets(Tcellname & " (2)").Name = WWcellname
err1:
If WWcellname = "" Then
MsgBox (Space(55) & "WARNING!!!" & vbNewLine & "The Work Week name you have entered is blank. Therefore, the work week you are trying to create will be named by its default name.")
ElseIf Pcellname = "" Then
MsgBox (Space(45) & "ERROR!!!" & vbNewLine & "The Previous Work Week name you have entered is blank.")
ElseIf Tcellname = "" Then
MsgBox (Space(35) & "ERROR!!!" & vbNewLine & "The Template name you have entered is blank.")
ElseIf Err.Number = 1004 Then
Application.DisplayAlerts = False
Sheets(Tcellname & " (2)").Delete
Application.DisplayAlerts = True
MsgBox (Space(20) & "ERROR!!!" & vbNewLine & "The Sheet Name already exists.")
ElseIf Err.Number = 9 Then
MsgBox (Space(65) & "ERROR!!!" & vbNewLine & "The Template you are trying to copy does not exist or the previous worksheet you have entered does not exist.")
End If
Worksheets(1).Select
End Sub
My situation is this, i want to have different error messages for an error that has the same error number. pls help
thanks
Sub CopyTemp()
Dim WWcellname As String
Dim Pcellname As String
Dim Tcellname As String
Dim Workshets As String
Dim Workshets1 As String
WWcellname = Range("B1").Value
Pcellname = Range("B2").Value
Tcellname = Range("B3").Value
On Error GoTo err1
Sheets(Tcellname).Select
Sheets(Tcellname).Copy Before:=Sheets(Pcellname)
Sheets(Tcellname & " (2)").Name = WWcellname
err1:
If WWcellname = "" Then
MsgBox (Space(55) & "WARNING!!!" & vbNewLine & "The Work Week name you have entered is blank. Therefore, the work week you are trying to create will be named by its default name.")
ElseIf Pcellname = "" Then
MsgBox (Space(45) & "ERROR!!!" & vbNewLine & "The Previous Work Week name you have entered is blank.")
ElseIf Tcellname = "" Then
MsgBox (Space(35) & "ERROR!!!" & vbNewLine & "The Template name you have entered is blank.")
ElseIf Err.Number = 1004 Then
Application.DisplayAlerts = False
Sheets(Tcellname & " (2)").Delete
Application.DisplayAlerts = True
MsgBox (Space(20) & "ERROR!!!" & vbNewLine & "The Sheet Name already exists.")
ElseIf Err.Number = 9 Then
MsgBox (Space(65) & "ERROR!!!" & vbNewLine & "The Template you are trying to copy does not exist or the previous worksheet you have entered does not exist.")
End If
Worksheets(1).Select
End Sub
Last edited: