Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Count only numbers from string

Posted on 2007-04-06
7
Medium Priority
?
231 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
[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
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 39

Accepted Solution

by:
stevbe earned 800 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 800 total points
ID: 18865704
I think the second
endif
is actually
next longpos
0
 
LVL 67

Assisted Solution

by:sirbounty
sirbounty earned 400 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
Does Your Cloud Backup Use Blockchain Technology?

Blockchain technology has already revolutionized finance thanks to Bitcoin. Now it's disrupting other areas, including the realm of data protection. Learn how blockchain is now being used to authenticate backup files and keep them safe from hackers.

 
LVL 39

Assisted Solution

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

Assisted Solution

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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

722 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