Substitute all letters of the alphabet

Rubber Beaked Woodpecker

Board Regular
Joined
Aug 30, 2015
Messages
203
Office Version
  1. 2021
Hi

I would like a formula that substitute all letters from the alphabet. I know I can do this using a rule for each letter but obviously that would create a very long formula.

Is there an easier way please?
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
When you say substitute, do you mean remove, or replace with something else? Either way, if you are still using 2016, I think it will be a long formula unless you use a UDF written in VBA.
 
Upvote 0
Then I think your best bet is VBA unless you have access to a more recent version of Office.
 
Upvote 0
So, are you open to a vba approach? If so, you could consider a user-defined function. Here is one. To implement ..
1. Right click the sheet name tab and choose "View Code".
2. In the Visual Basic window use the menu to Insert|Module
3. Copy and Paste the code below (you can use the icon at the top right of the code pane below) into the main right hand pane that opens at step 2.
4. Close the Visual Basic window.
5. Enter the formula as shown in the screen shot below and copy down.
6. Your workbook will need to be saved as a macro-enabled workbook (*.xlsm)

I took a punt about what you might want to do in relation to any space characters in the data, if they are possible. If it is not what you want, please detail what you do want.

VBA Code:
Function RemoveLetters(s As String) As String
  With CreateObject("VBSCript.RegExp")
    .Global = True
    .Pattern = "[A-Za-z]"
    RemoveLetters = Application.Trim(.Replace(s, ""))
  End With
End Function

RBW.xlsm
AB
1Sell 10 toys10
2What the heck!!??@@##!!!!??@@##!!
3 
4ABCDefgh 
523 abc 46 def 12323 46 123
Sheet1
Cell Formulas
RangeFormula
B1:B5B1=RemoveLetters(A1)
 
Upvote 0
For example:

VBA Code:
Function ReplaceAlpha(inputText As String) As String
   If Len(inputText) <> 0 Then
      Dim n As Long
      For n = 1 To 26
         inputText = Replace$(inputText, Chr(64 + n), "", , , vbTextCompare)
      Next n
      ReplaceAlpha = inputText
   End If
End Function
 
Upvote 0

Forum statistics

Threads
1,215,330
Messages
6,124,307
Members
449,151
Latest member
JOOJ

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