removing letters in vba

brett1337

New Member
Joined
Jun 9, 2009
Messages
21
I need to remove all the alpha text in a cell using a vba macro.

for example, cell A1 reads:

" january rate is $.045 "

Whereas I would like it to be

" $.045 "

Thank you in advance
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Note, you will end up with more than one leading space with this, because there are 4 spaces in your text before the $.045

Code:
Function RemoveAlpha(r As String)
With CreateObject("vbscript.regexp")
    .Pattern = "[A-Z]"
    .IgnoreCase = True
    .Global = True
    RemoveAlpha = .Replace(r, "")
End With
End Function

However, if you just want whatever the last word in the sentence is, this can be done quite easily with the following formula:

=TRIM(RIGHT(SUBSTITUTE(A2," ",REPT(" ",255)),254))

Excel Workbook
AB
1january rate is $.045$.045
2january rate is $.045$.045
3
Sheet1
 
Upvote 0
Thanks I'll play with these and decide which is best.

The spaces aren't a problem, I figured they would be there.
 
Upvote 0

Forum statistics

Threads
1,223,910
Messages
6,175,320
Members
452,635
Latest member
laura12345

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