Hi all!
I have a long column containg letters and numbers eg:
123stefd456 abc3467
hjjk4556 ghhk4gr57
I need a vba script which will filter out all the numbers and just leave letters in each cell.
“instr” does not take regex “[1-9]'” format as wildcard –how do I use “new regex” in vba as defined in vbscript ??? -or is there a direct way of doing with vba?
thanx
Smbs
![]() |
There are isolated problems with current patches, but they are well-known and documented on this site. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
-
regex—replace numbers (excel97+)
Home » Forums » AskWoody support » Productivity software by function » MS Excel and spreadsheet help » regex—replace numbers (excel97+)
- This topic has 8 replies, 4 voices, and was last updated 22 years, 1 month ago.
AuthorTopicWSsmbs
AskWoody LoungerApril 13, 2003 at 6:10 pm #386047Viewing 2 reply threadsAuthorReplies-
WSHansV
AskWoody LoungerApril 13, 2003 at 7:33 pm #668313The array formula wizards will probably come up with a method involving formulas only, no code. In the meantime, here is a procedure using standard Excel VBA that strips the digits 0 … 9 from the selected cells. It leaves everything else; if you want to leave only alphabetic characters, you can adapt the If … Then statement accordingly.
Sub RemoveDigits()
Dim oCell As Range
Dim strOldVal As String
Dim strNewVal As String
Dim strChar As String
Dim i As IntegerFor Each oCell In Selection
‘ Get current value
strOldVal = oCell.Value
‘ New value starts out empty
strNewVal = “”
‘ Loop through characters
For i = 1 To Len(strOldVal)
‘ Get i-th character
strChar = Mid(strOldVal, i, 1)
‘ Test if not numeric
If Not IsNumeric(strChar) Then
‘ It’s not a digit, so append to new value
strNewVal = strNewVal & strChar
End If
Next i
‘ Set new value
oCell.Value = strNewVal
Next oCell
End Sub -
WSJim Cone
AskWoody LoungerApril 13, 2003 at 8:03 pm #668317Smbs,
The following code works If all the extras characters are lower case and consist only of a to z.
It can be modified to remove other characters as necessary…Sub RemoveAlphasFromRange()
Dim ColRng As Range
Dim N As LongSet ColRng = Range(“C1:C1000”) ‘ Do not us an entire column
For N = 97 To 122 ‘ Character codes for lower case a to z
ColRng.Value = Application.Substitute(ColRng, Chr$(N), vbNullString)
Next ‘N
Set ColRng = Nothing
End SubRegards,
Jim Cone
San Francisco, CA
jim.coneXXX@rcn.comXXX -
WSHansV
AskWoody Lounger -
WSJim Cone
AskWoody LoungerApril 13, 2003 at 9:21 pm #668336Hans,
You are right and you know the answer, but for others…
Replace…
For N = 97 To 122 ‘removes lower case a to zwith…
For N = 48 to 57’ removes 0 to 9Also, adding this additional line, before the loop removes all spaces…
ColRng.Value = Application.Substitute(ColRng, Chr$(32, vbNullString)Regards,
Jim Cone -
WSsmbs
AskWoody Lounger
-
-
-
-
H. Legare Coleman
AskWoody PlusApril 13, 2003 at 8:07 pm #668319There are no VBA functions that use regular expressions. Therefore, you would need to do something like the code below which will do what you asked for all string values in column A:
Public Sub RemoveDigits() Dim oCell As Range Dim lngLastRow As Long Dim strOld As String, strChar As String, strNew As String lngLastRow = Worksheets("Sheet1").Range("A65536").End(xlUp).Row - 1 For Each oCell In Range(Worksheets("Sheet1").Range("A1"), Worksheets("Sheet1").Range("A1").Offset(lngLastRow)) If (Not oCell.HasFormula) And (Not IsNumeric(oCell.Value)) And (Not oCell.Value = "") Then strOld = oCell.Value strNew = "" Do While Len(strOld) > 0 strChar = Left(strOld, 1) strOld = Right(strOld, Len(strOld) - 1) If Not IsNumeric(strChar) Then strNew = strNew & strChar End If Loop oCell.Value = strNew End If Next oCell End Sub
Viewing 2 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
-
What is wrong with simple approach? (Awaiting moderation)
by
WSSpoke36
1 hour, 38 minutes ago -
Frustrating search behavior with Outlook
by
MrJimPhelps
4 hours, 59 minutes ago -
June 2025 Office non-Security Updates
by
PKCano
8 hours, 12 minutes ago -
Secure Boot Update Fails after KB5058405 Installed
by
SteveIT
52 minutes ago -
Firefox Red Panda Fun Stuff
by
Lars220
8 hours, 8 minutes ago -
How start headers and page numbers on page 3?
by
Davidhs
18 hours, 32 minutes ago -
Attack on LexisNexis Risk Solutions exposes data on 300k +
by
Nibbled To Death By Ducks
13 hours, 8 minutes ago -
Windows 11 Insider Preview build 26200.5622 released to DEV
by
joep517
1 day, 3 hours ago -
Windows 11 Insider Preview build 26120.4230 (24H2) released to BETA
by
joep517
1 day, 3 hours ago -
MS Excel 2019 Now Prompts to Back Up With OneDrive
by
lmacri
16 hours, 56 minutes ago -
Firefox 139
by
Charlie
9 hours, 31 minutes ago -
Who knows what?
by
Will Fastie
4 hours, 4 minutes ago -
My top ten underappreciated features in Office
by
Peter Deegan
1 day, 3 hours ago -
WAU Manager — It’s your computer, you are in charge!
by
Deanna McElveen
22 hours, 22 minutes ago -
Misbehaving devices
by
Susan Bradley
3 hours, 6 minutes ago -
.NET 8.0 Desktop Runtime (v8.0.16) – Windows x86 Installer
by
WSmeyerbos
2 days, 9 hours ago -
Neowin poll : What do you plan to do on Windows 10 EOS
by
Alex5723
7 hours, 15 minutes ago -
May 31, 2025—KB5062170 (OS Builds 22621.5415 and 22631.5415 Out-of-band
by
Alex5723
2 days, 8 hours ago -
Discover the Best AI Tools for Everything
by
Alex5723
1 day, 7 hours ago -
Edge Seems To Be Gaining Weight
by
bbearren
1 day, 22 hours ago -
Rufus is available from the MSFT Store
by
PL1
2 days, 6 hours ago -
Microsoft : Ending USB-C® Port Confusion
by
Alex5723
3 days, 9 hours ago -
KB5061768 update for Intel vPro processor
by
drmark
1 day, 9 hours ago -
Outlook 365 classic has exhausted all shared resources
by
drmark
1 day, 8 hours ago -
My Simple Word 2010 Macro Is Not Working
by
mbennett555
3 days, 5 hours ago -
Office gets current release
by
Susan Bradley
3 days, 8 hours ago -
FBI: Still Using One of These Old Routers? It’s Vulnerable to Hackers
by
Alex5723
4 days, 22 hours ago -
Windows AI Local Only no NPU required!
by
RetiredGeek
4 days, 6 hours ago -
Stop the OneDrive defaults
by
CWBillow
4 days, 22 hours ago -
Windows 11 Insider Preview build 27868 released to Canary
by
joep517
5 days, 8 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.