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
![]() |
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 |
-
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
-
Does windows update component store “self heal”? (Awaiting moderation)
by
Mike Cross
4 minutes ago -
Windows 11 Insider Preview build 27858 released to Canary
by
joep517
21 minutes ago -
Pwn2Own Berlin 2025: Day One Results
by
Alex5723
53 minutes ago -
Windows 10 might repeatedly display the BitLocker recovery screen at startup
by
Susan Bradley
28 minutes ago -
Windows 11 Insider Preview Build 22631.5409 (23H2) released to Release Preview
by
joep517
3 hours, 3 minutes ago -
Windows 10 Build 19045.5912 (22H2) to Release Preview Channel
by
joep517
3 hours, 4 minutes ago -
Kevin Beaumont on Microsoft Recall
by
Susan Bradley
10 hours, 5 minutes ago -
The Surface Laptop Studio 2 is no longer being manufactured
by
Alex5723
11 hours, 12 minutes ago -
0Patch, where to begin
by
cassel23
5 hours, 14 minutes ago -
CFPB Quietly Kills Rule to Shield Americans From Data Brokers
by
Alex5723
1 day ago -
89 million Steam account details just got leaked,
by
Alex5723
12 hours, 35 minutes ago -
KB5058405: Linux – Windows dual boot SBAT bug, resolved with May 2025 update
by
Alex5723
1 day, 9 hours ago -
A Validation (were one needed) of Prudent Patching
by
Nibbled To Death By Ducks
1 day ago -
Master Patch Listing for May 13, 2025
by
Susan Bradley
11 hours, 29 minutes ago -
Installer program can’t read my registry
by
Peobody
6 hours, 27 minutes ago -
How to keep Outlook (new) in off position for Windows 11
by
EspressoWillie
22 hours, 8 minutes ago -
Intel : CVE-2024-45332, CVE-2024-43420, CVE-2025-20623
by
Alex5723
1 day, 5 hours ago -
False error message from eMClient
by
WSSebastian42
1 day, 20 hours ago -
Awoke to a rebooted Mac (crashed?)
by
rebop2020
2 days, 5 hours ago -
Office 2021 Perpetual for Mac
by
rebop2020
2 days, 6 hours ago -
AutoSave is for Microsoft, not for you
by
Will Fastie
1 day, 3 hours ago -
Difface : Reconstruction of 3D Human Facial Images from DNA Sequence
by
Alex5723
2 days, 10 hours ago -
Seven things we learned from WhatsApp vs. NSO Group spyware lawsuit
by
Alex5723
1 day, 11 hours ago -
Outdated Laptop
by
jdamkeene
2 days, 15 hours ago -
Updating Keepass2Android
by
CBFPD-Chief115
2 days, 21 hours ago -
Another big Microsoft layoff
by
Charlie
2 days, 20 hours ago -
PowerShell to detect NPU – Testers Needed
by
RetiredGeek
18 hours, 13 minutes ago -
May 2025 updates are out
by
Susan Bradley
40 minutes ago -
Windows 11 Insider Preview build 26200.5600 released to DEV
by
joep517
3 days, 2 hours ago -
Windows 11 Insider Preview build 26120.3964 (24H2) released to BETA
by
joep517
3 days, 2 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.