Macro to remove all the numbers from cells in a column

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
3,194
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hi Everyone,

I have data that come in written like this:

"T_Tester_Grey_600cm_66cm"
or
"Test_Bed_1600cm_266cm"

I want all the words but not the numbers so
"T_Tester_Grey"
"Test_Bed"

So I'd like a macro that can go down column C and either change all these or even better put the changed words into column Z

please help if you can
Tony
 

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
Do you really need VBA for it? It can be done by simple UDF (to put into cells in col. Z in your case)

VBA Code:
Function FirstDigit(strData As String) As Integer
    Dim RE As Object, REMatches As Object
    Set RE = CreateObject("vbscript.regexp")
    With RE
        .Pattern = "[0-9]"
    End With
    Set REMatches = RE.Execute(strData)
    FirstDigit = REMatches(0).FirstIndex
End Function

Book1
AB
1T_Tester_Grey_600cm_66cmT_Tester_Grey
2Test_Bed_1600cm_266cmTest_Bed
Sheet1
Cell Formulas
RangeFormula
B1:B2B1=LEFT(A1,FirstDigit(A1)-1)
 
Upvote 0
KOKOSEK, if You don't mind.
Happy to help.
 
Upvote 0
Hi
VBA option
VBA Code:
Sub change()
Dim a As Variant
Dim i As Long
   a = Range("C1").Resize(Cells(Rows.Count, 3).End(xlUp).Row)
    With CreateObject("vbscript.regexp")
         .Pattern = "\_\d+.*"
            For i = 1 To UBound(a)
            a(i, 1) = .Replace(a(i, 1), "")
            Next
    End With
    Range("Z1").Resize(UBound(a)) = a
End Sub
 
Upvote 0
Solution
Thank you Mohadin,
this is actually even better for what i'm trying to do,
Thanks very much
Tony
 
Upvote 0
You are welcome Tony
And thank you for the feedback
Be happy and safe
 
Upvote 0

Forum statistics

Threads
1,214,924
Messages
6,122,293
Members
449,077
Latest member
Rkmenon

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