Formula for removing numbers from a cell

MARK858

MrExcel MVP
Joined
Nov 12, 2010
Messages
16,165
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
Hi there, hopefully an easy question for someone out there. Does anyone know a formula to remove the numbers from a cell with the layout as below;

AB19S02 becomes ABS
BG36Z07 becomes BGZ
GH68L75 becomes GHL

and so on....
The cells are aligned to the right if that is any help
Cheers in advance for any suggestions.
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
If they are always of the form
< letter >< letter >< digit >< digit >< letter >< digit >< digit >

you could use the formula =LEFT(A1,2)&MID(A1, 5,1)
 
Upvote 0
select whatever cells you want to get rid of the numbers and then start this macro. I would suggest making it a hotkey. i.e. ctrl+d or ctrl+m

Code:
Sub GetRidOfNumbers()
    For i = 1 To 9
        selection.Replace what:=i, replacement:="", lookat:= _
        xlPart, searchorder:=xlByRows, MatchCase:=False, searchformat:=False, _
        ReplaceFormat:=False
    Next i
End Function
 
Upvote 0
replace should work if you trying to get rid of numbers and you dont have to use vba to do it....but if you do don't forget zer0

use mikerickson method if it's first two letters and fifth

good luck
 
Upvote 0
Without a loop:

Code:
Function OnlyLetters(r As String) As String
With CreateObject("vbscript.regexp")
    .Pattern = "[^A-Z]"
    .IgnoreCase = True
    .Global = True
    OnlyLetters = .Replace(r, "")
End With
End Function
 
Upvote 0
Thanks to both of you for your help and speedy replies. They both work perfectly.
Rsxchin, I had to make a couple of adaptations to your code
A) changing
For i = 1 To 9 to For i = 0 To 9
B) Changing
End Function to End Sub
 
Upvote 0
Hotpepper,thanks for your suggestion I am getting it to work on a single cell well enough but having a bit of trouble getting it to work on a range but I'll have a proper play when I have a bit more time later in the week.

Rsxchin, your solution was fine it just needed minor tweaking
 
Upvote 0
Code:
Sub test()
Dim c As Range
For Each c In Range("A1:A1000")
    c = OnlyLetters(c.Text)
Next
End Sub

Function OnlyLetters(r As String) As String
With CreateObject("vbscript.regexp")
    .Pattern = "[^A-Z]"
    .IgnoreCase = True
    .Global = True
    OnlyLetters = .Replace(r, "")
End With
End Function
 
Upvote 0

Forum statistics

Threads
1,214,525
Messages
6,120,051
Members
448,940
Latest member
mdusw

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top