I’m trying to locate several possible combinations of numbers within a string of text. The string of text could be any length and the numbers can start at any position within the string. The numbers I’m looking for can be any number and be 9 digits in length, 10 digits, 11 digits, 12 digits or 16 digits. These numbers may also have spaces or dashes within them at any place. Since there are so many possible combinations that could occur. I’m a little stumped on what options I could use. I’ve considered using Instr() as well as looking for values that are Like “######” (numbers) but not having any real luck with this. For anybody looking for a challenge, I could certainly use your help trying to solve this. Basically once I find a number combination in the string of text. I would just need to shade that cell to call it out. I’m currently using excel 2003 on Windows XP. Thanks to anybody offering up any suggestions.
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
-
Find 7 digit number in string of text
Home » Forums » AskWoody support » Productivity software by function » MS Excel and spreadsheet help » Find 7 digit number in string of text
- This topic has 8 replies, 5 voices, and was last updated 14 years, 8 months ago.
Viewing 7 reply threadsAuthorReplies-
WSAndrewKKWalker
AskWoody Lounger -
WSgrugeon
AskWoody LoungerJune 23, 2010 at 7:52 pm #1230547Try this
I have included “(” and “)” as not significant but you can take them out if I have guessed wrong.
You need to select the cells to be tested and then run the sub.
Option Explicit
Sub colorPhonCells()
Dim s As String
Dim v As String
Dim c As Range
Dim n As Integer
Dim j As IntegerFor Each c In Selection
s = c.Text
For j = 1 To Len(s)
v = Mid(s, j, 1)
Select Case v
Case “0” To “9”
n = n + 1
If n > 8 Then c.Interior.Color = vbYellow
Case “-“, ” “, “(“, “)”
Case Else
n = 0
End Select
Next jNext c
End Sub -
WSrory
AskWoody Lounger -
WSb0bito
AskWoody LoungerJune 24, 2010 at 8:19 am #1230608Andrew, Rory, David – Thank you all for your responses. I’m sure I could have included some more description in what I was performing this check against. Unfortunatly I couldn’t post anything due to the sensitive nature of the data I’m working with and I didn’t have any examples at the time to post. From David’s response, I was able to work out a solution by slightly modifying what David suggested. Resetting the n counter when ever the v value was not a number space or dash. This allowed me to find a string of numbers, dashes and spaces with no letters in between. I think this should work. Below is what I have in case you find somebody else at a later time needs to perform a search of this type. Thanks again for your time and responses.
By the way Rory. What did you mean by RegExp?? I’m not familiar with that.
Option Explicit
Sub colorPhonCells()
Dim s As String
Dim v As String
Dim c As Range
Dim n As Integer
Dim j As Integer
Dim r As IntegerFor r = 2 To 30000
If Cells(r, 5).Value = “” Then Exit For
Cells(r, 5).Select
n = 0
For Each c In Selection
s = c.Text
For j = 1 To Len(s)
v = Mid(s, j, 1)
If v Like “#” Or v Like ” ” Or v Like “-” Then
Select Case v
Case “0” To “9”
n = n + 1
If n > 8 Then c.Interior.Color = vbYellow
Case “-“, ” ”
Case Else
n = 0
End Select
Else
n = 0
End If
Next j
Next c
Next r
End Sub -
WSrory
AskWoody LoungerJune 24, 2010 at 8:26 am #1230615I was referring to Regular Expressions – see http://www.regular-expressions.info]this page[/url] for example.
-
zeddy
AskWoody_MVP -
WSrory
AskWoody LoungerJune 26, 2010 at 10:45 am #1231139I’ll have a go 🙂
After several attempts, I’m abandoning trying to do a live link since it gets converted into garbage. It’s:
http://www.regular-expressions.info -
zeddy
AskWoody_MVP
Viewing 7 reply threads -

Plus Membership
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Get Plus!
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Search Newsletters
Search Forums
View the Forum
Search for Topics
Recent Topics
-
Toll road scams are back: What to do if you get a text saying you owe money
by
Alex5723
1 hour, 49 minutes ago -
Windows update download issue…
by
CAS
1 hour, 22 minutes ago -
WUMGR & KB5053602 UPDATE/INSTALL FAIL
by
dataman1701
42 minutes ago -
Finding Microsoft Office 2021 product key
by
Kathy Stevens
5 hours, 27 minutes ago -
Over-the-Top solves it!
by
RetiredGeek
15 hours, 57 minutes ago -
To Susan – Woody Leonhard, the “Lionhearted”
by
Myst
22 hours, 58 minutes ago -
Extracting Data From All Sheets
by
WSJon5
1 day ago -
Use wushowhide in Windows 11 24H2?
by
Tex265
2 hours, 39 minutes ago -
Hacktool:Win32/Winring0
by
Marvel Wars
11 hours, 23 minutes ago -
Microsoft Defender as Primary Security Question
by
blueboy714
6 hours, 8 minutes ago -
USB printers might print random text with the January 2025 preview update
by
Alex5723
5 hours, 45 minutes ago -
Google’s 10-year-old Chromecast is busted, but a fix is coming
by
Alex5723
1 day, 12 hours ago -
Expand the taskbar?
by
CWBillow
1 day, 12 hours ago -
Gregory Forrest “Woody” Leonhard (1951-2025)
by
Susan Bradley
2 hours, 50 minutes ago -
March 2025 updates are out
by
Susan Bradley
52 minutes ago -
Windows 11 Insider Preview build 26120.3380 released to DEV and BETA
by
joep517
2 days, 6 hours ago -
Update Firefox to prevent add-ons issues from root certificate expiration
by
Alex5723
2 days, 13 hours ago -
Latest Firefox requires Password on start up
by
Gordski
2 hours, 36 minutes ago -
Resolved : AutoCAD 2022 might not open after updating to 24H2
by
Alex5723
3 days, 2 hours ago -
Missing api-ms-win-core-libraryloader-11-2-1.dll
by
IreneLinda
2 days, 1 hour ago -
How Much Daylight have YOU Saved?
by
Nibbled To Death By Ducks
2 days, 4 hours ago -
A brief history of Windows Settings
by
Simon Bisson
1 day, 21 hours ago -
Thunderbolt is not just for monitors
by
Ben Myers
1 day, 20 hours ago -
Password Generators — Your first line of defense
by
Deanna McElveen
2 days, 1 hour ago -
AskWoody at the computer museum
by
Will Fastie
1 day, 1 hour ago -
Planning for the unexpected
by
Susan Bradley
2 days, 2 hours ago -
Which printer type is the better one to buy?
by
Bob99
3 days, 4 hours ago -
Upgrading the web server
by
Susan Bradley
3 days, 2 hours ago -
New Windows 11 24H2 Setup – Initial Win Update prevention settings?
by
Tex265
3 days, 21 hours ago -
Creating a Google account
by
DavidofIN
3 days, 20 hours ago
Recent blog posts
Key Links
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.