shahdelsol
Active Member
- Joined
- Jul 21, 2009
- Messages
- 276
- Office Version
- 365
- Platform
- Windows
I am using this vba and I want to add one line of code if "cancel" selected or if "nothing "entered then exit the sub. I tried to add this
If Inputbox (msg) = ""
exit sub
end if
But it doesn't work quite well. I appreciate anyone can help.
If Inputbox (msg) = ""
exit sub
end if
But it doesn't work quite well. I appreciate anyone can help.
VBA Code:
Dim MonEntry As Integer
Dim Msg As String
Const MinMonth As Integer = 1
Const MaxMonth As Integer = 12
Msg = "What month are your creating a new tab for?"
Msg = Msg & vbNewLine
Msg = Msg & "Please enter number for the month between " & MinMonth & " and " & MaxMonth
Do
MonEntry = InputBox(Msg)
If IsNumeric(MonEntry) Then
If MonEntry >= MinMonth And MonEntry <= MaxMonth Then Exit Do
End If
Msg = "wrong entry"
Msg = Msg & vbNewLine
Msg = Msg & "Please enter a valid number for the month!"
Msg = Msg & vbNewLine
Msg = Msg & "The number for the month must be between " & MinMonth & " and " & MaxMonth
Loop
Worksheets("TMP").Copy after:=Sheets(Worksheets.Count)
ActiveSheet.Name = Format(28 * MonEntry, "mmm ") & Year(Now)
End If
End Sub