Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Insert Leading Characters If String Is Only 7 Characters Paperback Writer Excel Discussion (Misc queries) 2 April 21st 09 09:07 PM
Highlighting special characters in a string Cynthia Excel Programming 7 November 11th 08 12:51 PM
Special characters in a string variable [email protected] Excel Programming 1 August 4th 06 08:36 PM
String Function 'Like' and Special Characters Vagabond Software Excel Programming 3 June 12th 04 02:02 AM
Escape for special characters in string Jag Man Excel Programming 2 January 2nd 04 03:56 AM


All times are GMT +1. The time now is 10:49 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"