replacing number from the text

lezawang

Well-known Member
Joined
Mar 27, 2016
Messages
1,805
Office Version
  1. 2016
Platform
  1. Windows
Hi
What is the best way to get rid of numbers in the column below? I only want "John" name to appear without numbers. I can do Find/Replace, or use nested Substitute() but has to be nested. Is there better way to do that? Thank you very much

[TABLE="class: grid, width: 64"]
<colgroup><col width="64" style="width:48pt"> </colgroup><tbody>[TR]
[TD="width: 64"]john1[/TD]
[/TR]
[TR]
[TD]john2[/TD]
[/TR]
[TR]
[TD]john3[/TD]
[/TR]
[TR]
[TD]john4[/TD]
[/TR]
[TR]
[TD]john5[/TD]
[/TR]
[TR]
[TD]john6[/TD]
[/TR]
[TR]
[TD]john7[/TD]
[/TR]
[TR]
[TD]john8[/TD]
[/TR]
[TR]
[TD]john9[/TD]
[/TR]
[TR]
[TD]john10[/TD]
[/TR]
[TR]
[TD]john11[/TD]
[/TR]
[TR]
[TD]john12[/TD]
[/TR]
[TR]
[TD]john13[/TD]
[/TR]
[TR]
[TD]john14[/TD]
[/TR]
[TR]
[TD]john15[/TD]
[/TR]
[TR]
[TD]john16[/TD]
[/TR]
[TR]
[TD]john17[/TD]
[/TR]
[TR]
[TD]john18[/TD]
[/TR]
[TR]
[TD]john19[/TD]
[/TR]
[TR]
[TD]john20[/TD]
[/TR]
[TR]
[TD]john21[/TD]
[/TR]
[TR]
[TD]john22[/TD]
[/TR]
[TR]
[TD]john23[/TD]
[/TR]
[TR]
[TD]john24[/TD]
[/TR]
[TR]
[TD]john25[/TD]
[/TR]
[TR]
[TD]john26[/TD]
[/TR]
[TR]
[TD]john27[/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Hi lezawang,

You can use a UDF to replace any non alphabetical characters

Code:
Function REPLACENUM(txt As String) As String
    With CreateObject("VBScript.RegExp")
        .Global = True
        .Pattern = "[^a-zA-Z]"
        REPLACENUM = .Replace(txt, "")
    End With
End Function
 
Last edited:
Upvote 0
Thank you very much for your help. Could you please break the code down. I did not understand this part
.Pattern = "[^a-zA-Z]"

Also what is UDF? Thanks once again.


You can use a UDF to replace any non alphabetical characters

Code:
Function REPLACENUM(txt As String) As String
    With CreateObject("VBScript.RegExp")
        .Global = True
        .Pattern = "[^a-zA-Z]"
        REPLACENUM = .Replace(txt, "")
    End With
End Function
 
Last edited:
Upvote 0
Thank you very much for your help. Could you please break the code down. I did not understand this part
.Pattern = "[^a-zA-Z]"

Also what is UDF? Thanks once again.

Yeah no worries, the "[^a-zA-Z]" part basically looks for any character in your string that isn't between a-z or A-Z. So e.g. "he11o w0rld" would pick up "11 0" (includes the space)
Then the code replaces all of this text with "" (blank) so in this instance "heowrld" would be the new string after calling the function.

A UDF is a User Defined Function, a function that is created by the user (your very own function if you will)

I hope this helps and solves the problem!
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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