Solved

Count only numbers from string

Posted on 2007-04-06
7
226 Views
Last Modified: 2008-02-07
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
Comment
Question by:mustish1
  • 3
  • 3
7 Comments
 
LVL 39

Accepted Solution

by:
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

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

Assisted Solution

by:sirbounty
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
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 
LVL 39

Assisted Solution

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

Assisted Solution

by:jerryb30
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

by:stevbe
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

by:jerryb30
ID: 18865839
So i did.
Thanks.
0

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question