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
-
Installer program can’t read my registry
by
Peobody
10 minutes ago -
How to keep Outlook (new) in off position for Windows 11
by
EspressoWillie
2 hours, 19 minutes ago -
Intel : CVE-2024-45332, CVE-2024-43420, CVE-2025-20623
by
Alex5723
3 minutes ago -
False error message from eMClient
by
WSSebastian42
10 hours, 46 minutes ago -
Awoke to a rebooted Mac (crashed?)
by
rebop2020
9 hours, 2 minutes ago -
Office 2021 Perpetual for Mac
by
rebop2020
10 hours, 14 minutes ago -
AutoSave is for Microsoft, not for you
by
Will Fastie
1 hour, 34 minutes ago -
Difface : Reconstruction of 3D Human Facial Images from DNA Sequence
by
Alex5723
13 hours, 46 minutes ago -
Seven things we learned from WhatsApp vs. NSO Group spyware lawsuit
by
Alex5723
14 hours, 8 minutes ago -
Outdated Laptop
by
jdamkeene
19 hours, 12 minutes ago -
Updating Keepass2Android
by
CBFPD-Chief115
1 day ago -
Another big Microsoft layoff
by
Charlie
1 day ago -
PowerShell to detect NPU – Testers Needed
by
RetiredGeek
3 hours, 42 minutes ago -
May 2025 updates are out
by
Susan Bradley
2 minutes ago -
Windows 11 Insider Preview build 26200.5600 released to DEV
by
joep517
1 day, 6 hours ago -
Windows 11 Insider Preview build 26120.3964 (24H2) released to BETA
by
joep517
1 day, 6 hours ago -
Drivers suggested via Windows Update
by
Tex265
1 day, 6 hours ago -
Thunderbird release notes for 128 esr have disappeared
by
EricB
1 day, 3 hours ago -
CISA mutes own website, shifts routine cyber alerts to X, RSS, email
by
Nibbled To Death By Ducks
1 day, 13 hours ago -
Apple releases 18.5
by
Susan Bradley
1 day, 7 hours ago -
Fedora Linux 40 will go end of life for updates and support on 2025-05-13.
by
Alex5723
1 day, 14 hours ago -
How a new type of AI is helping police skirt facial recognition bans
by
Alex5723
1 day, 15 hours ago -
Windows 7 ISO /Windows 10 ISO
by
ECWS
22 hours, 32 minutes ago -
No HP software folders
by
fpefpe
1 day, 22 hours ago -
Which antivirus apps and VPNs are the most secure in 2025?
by
B. Livingston
20 hours, 17 minutes ago -
Stay connected anywhere
by
Peter Deegan
2 days, 4 hours ago -
Copilot, under the table
by
Will Fastie
6 hours, 45 minutes ago -
The Windows experience
by
Will Fastie
2 days, 10 hours ago -
A tale of two operating systems
by
Susan Bradley
14 hours, 48 minutes ago -
Microsoft : Resolving Blue Screen errors in Windows
by
Alex5723
2 days, 15 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.