VBA - Remove all alphabetical characters from range.

NichoD

Board Regular
Joined
Jul 31, 2022
Messages
54
Office Version
  1. 2016
Platform
  1. Windows
Hello, I have a macro which picks ups different strings. But I only want to keep the numbers and commas from those strings and reomove any alphabetical character.


The strings are plotted into range L25:L38.

Thank you in advance and merry christmas!
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
To just replace letters, you could use something like:

VBA Code:
Sub replaceLetters()
for n = 1 to 26
 range("L25:L38").Replace chr(64 + n), "", xlpart,,false
 next n
end sub
 
Upvote 0
Give this a try with a copy of your worksheet. It should replace any characters other than digits 0 to 9 and commas

VBA Code:
Sub NumsOnly()
  Dim RX As Object
  Dim a As Variant
  Dim i As Long
 
  Set RX = CreateObject("VBScript.RegExp")
  RX.Global = True
  RX.Pattern = "[^0-9\,]"
  With Range("L25:L38")
    a = .Value
    For i = 1 To UBound(a)
      a(i, 1) = RX.Replace(a(i, 1), "")
    Next i
    .Value = a
  End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,596
Messages
6,125,732
Members
449,255
Latest member
whatdoido

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