Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Checking for special characters in a string
Here is a more compact function that works exactly like your function
does... Function HasBadChar(S As String) As Boolean HasBadChar = S Like "*[!0-9A-Za-z_]*" End Function -- Rick (MVP - Excel) "Chip Pearson" wrote in message ... You can use a function like Function HasBadChar(S As String) As Boolean Dim N As Long For N = 1 To Len(S) Select Case Mid(S, N, 1) Case "A" To "Z", "a" To "z", "0" To "9", "_" ' OK Case Else HasBadChar = True Exit Function End Select Next N HasBadChar = False End Function It will return True if there is any character in string S other than letters, numbers, and underscores. If the string has no other characters, it returns False. Cordially, Chip Pearson Microsoft Most Valuable Professional Excel Product Group, 1998 - 2009 Pearson Software Consulting, LLC www.cpearson.com (email on web site) On Wed, 4 Feb 2009 12:14:02 -0800, John wrote: How do I check a string to see if it contains any special characters like @$% etc? I'm using InputBox to request a name that will be used to define a range name and range names can consist of alpha, numeric and underscore characters only. I appreciate your help, -John |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Insert Leading Characters If String Is Only 7 Characters | Excel Discussion (Misc queries) | |||
Highlighting special characters in a string | Excel Programming | |||
Special characters in a string variable | Excel Programming | |||
String Function 'Like' and Special Characters | Excel Programming | |||
Escape for special characters in string | Excel Programming |