LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default Looking for String Function

On Thu, 9 Nov 2006 10:11:02 -0800, Chaplain Doug
wrote:

Excel 2003. What VBA string function(s) can I use to accomplish the following:

I want to pass a string that may or may not contain a telephone number. I
want to check to see if it is indeed a telephone number. That is, I want to
check to see if the string contains only telephone type info (i.e.,
0123456789()- ) or conversely, I want to check if the string contains
non-telephone type info (i.e., alpha). How can I accomplish this? Thanks
for any help.


You can either check things they way you describe. You would loop through each
character in the text string and test it:

======================
Const sAllow As String = "[- 0-9()]"
Dim i As Long
Dim sTest As String

For i = 1 To Len(sTest)
If Not Mid(sTest, i, 1) Like sAllow Then
TelNo = False
Exit (function or sub)
End If
Next i

TelNo = True
========================

Or you could construct a more complex test to better define exactly what a
valid phone number might consist of.

For example, some valid phone numbers might be:

123-4567
123 4567
1234567
1-123-4567
1-603-123-4567
1(123) 456-7890

and maybe even

1 123 456 7890 x 1234

But something like

1234 would not be a valid phone number

And if you are not in the US, there may be even more variations.
--ron
 
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
Function to evaluate function as string Basil Excel Worksheet Functions 3 September 18th 09 10:43 AM
string function help Eelinla Excel Discussion (Misc queries) 5 April 21st 07 08:26 PM
VBA function : How to search a string in another string? bibi-phoque Excel Programming 5 April 19th 05 06:24 PM
Add Function to String Ronbo Excel Worksheet Functions 2 February 22nd 05 05:33 AM
String Function Brenda Excel Programming 5 February 4th 05 03:24 AM


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

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

About Us

"It's about Microsoft Excel"