I have a spreadsheet with a macro to add new countries. The macro adds a new sheet for each country and users enter the name into an Input Box.
I have the code to reject country names with spaces (because it messes up later steps) but special characters other than underscore also mess it up.
I added code for the two special characters someone tried to use, but is there a simple way to check the string they enter for multiple disallowed characters instead of having an ElseIf for each special character I want to disallow?
I have searched many many times for a solution on google, but all the answers I find are either really old and no longer work or far beyond my google-learned VBA skills to adapt to my workbook.
The code I have is
I have the code to reject country names with spaces (because it messes up later steps) but special characters other than underscore also mess it up.
I added code for the two special characters someone tried to use, but is there a simple way to check the string they enter for multiple disallowed characters instead of having an ElseIf for each special character I want to disallow?
I have searched many many times for a solution on google, but all the answers I find are either really old and no longer work or far beyond my google-learned VBA skills to adapt to my workbook.
The code I have is
Code:
Dim response As String
response = InputBox("Country Name (no spaces)")
Dim errormess As String
errormess = "Do not use spaces or special characters (except underscore) in country names."
If InStr(1, response, " ") > 0 Then
MsgBox (errormess)
Exit Sub
ElseIf InStr(1, response, "-") > 0 Then
MsgBox (errormess)
Exit Sub
ElseIf InStr(1, response, "&") > 0 Then
MsgBox (errormess)
Exit Sub
Else
Sheets("aaSiteTemplate").Copy Before:=Sheets("aaSiteTemplate")
ActiveSheet.Range("A1") = response
End If
ActiveSheet.Name = response