Sub test() '''Special Character Section''' Dim special_charArr() As String Dim special_char As String special_char = "!,@,#,$,%,^,&,*,+,/,\,;,:" special_charArr() = Split(special_char, ",") '''Special Character Section''' char = "#" For Each Key In special_charArr special = InStr(char, Key) If special = 1 Then MsgBox char & " = #" End If Next End Sub
You can use RegEx but I found the solution less robust since I wanted special use cases for individual special_chars:
Function IsValidName(strData As String) As Boolean Dim RE As Object, REMatches As Object Set RE = CreateObject("vbscript.regexp") With RE .MultiLine = False .Global = True .IgnoreCase = True .Pattern = "[^a-zA-Z0-9]" End With IsValidName = Not RE.Test(strData) End Function