Solved

Count only numbers from string

Posted on 2007-04-06
229 Views
Hi: Is there any way thru VBA code i can know only the length of numbers from the string. I mean the length of string (only numbers) in str1=5 and the length of string str2=8 and length of string str3=10 and length of string str4=10

str1="12334redf"
str2="12345678"
str3="736-122-5880
str4="(631)656-0978

Thanks.
0
Question by:mustish1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 3
• 3

LVL 39

Accepted Solution

stevbe earned 200 total points
ID: 18865699
Public Function NumberCount(DataIn As String) As Long
Dim lngCount As Long
Dim lngPos As Long

For lngPos = 1 To Len(DataIn)
If IsNumeric(Mid(DataIn, lngPos, 1) Then
lngCount = lngCount + 1
End If
End If

NumberCount = lngCount

End Function
0

LVL 26

Assisted Solution

jerryb30 earned 200 total points
ID: 18865704
I think the second
endif
is actually
next longpos
0

LVL 67

Assisted Solution

sirbounty earned 100 total points
ID: 18865706
Something like this as an example...

str1 = "12334redf"
For x = 1 To Len(str1)
If IsNumeric(Mid(str1, x, 1)) Then
cnt = cnt + 1
End If
Next
0

LVL 39

Assisted Solution

stevbe earned 200 total points
ID: 18865726
what jerry said :-)
0

LVL 26

Assisted Solution

jerryb30 earned 200 total points
ID: 18865735
Steve:
I had a solution exactly like yours and refreshed. Would hae been in same minute, but you had me beat.....
0

LVL 39

Expert Comment

ID: 18865766
and that's what I get for typing too fast ... I made the function on the fly, you should get a split on this :-)
0

LVL 26

Expert Comment

ID: 18865839
So i did.
Thanks.
0

Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.