Substitute Alphanumeric Values

martinmc

New Member
Joined
Apr 21, 2019
Messages
16
Hi, Is there any other alternative or shorter solution for rewriting the below formula example.i have read in an older post that the SUBSTITUTE function cannot handle the "old_text" part as an array{1,2,3,4,5,6,7,8,9,0}
Thanks In Advance.

A1B2C3D4E5F6G7H8J9K0
=SUBSTITUTE(SUBSTITUTE(SUBSTITUTE( SUBSTITUTE( SUBSTITUTE(SUBSTITUTE( SUBSTITUTE( SUBSTITUTE( SUBSTITUTE( SUBSTITUTE(A1,0,""),1,""), 2,""),3,""),4,""), 5,""),6,""),7,""),8,""),9,"")
Result In B1
ABCDEFGHJK

<tbody>
</tbody>

<tbody>
</tbody>
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Hi martinmc,

If you have Office 365 or excel 2016 latest updated version you would have TEXTJOIN function, then below would be a shorter version of formula:

Code:
=TEXTJOIN("",TRUE,MID(A1,{1,3,5,7,9,11,13,15,17,19},1))
 
Upvote 0
If you don't have TEXTJOIN available to you, this UDF will work.

Code:
Function TextOnly(pWorkRng As Range) As String
Dim xValue As String
Dim OutValue As String
xValue = pWorkRng.Value
For xIndex = 1 To VBA.Len(xValue)
    If Not VBA.IsNumeric(VBA.Mid(xValue, xIndex, 1)) Then
        OutValue = OutValue & VBA.Mid(xValue, xIndex, 1)
    End If
Next
TextOnly = OutValue
End Function

Another alternative is to install the ASAP Utilities and they have a text function that will handle the entire worksheet.
 
Upvote 0
Next option is PowerQuery (Get&Transform):

rawResult
A1B2C3D4E5F6G7H8J9K0ABCDEFGHJK

Code:
[SIZE=1]// Table1
let
    C2R = List.Transform({48..57}, each Character.FromNumber(_)),
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    Text = Table.AddColumn(Table.ExpandListColumn(Table.TransformColumns(Source, {{"raw", Splitter.SplitTextByRepeatedLengths(1), let itemType = (type nullable text) meta [Serialized.Text = true] in type {itemType}}}), "raw"), "Text", each Text.Trim([raw],C2R)),
    Result = Table.RenameColumns(Table.FromList(Table.ToColumns(Table.SelectColumns(Table.SelectRows(Text, each ([Text] <> "")),{"Text"})), Splitter.SplitByNothing(), null, null, ExtraValues.Error),{{"Column1", "Result"}}),
    Extract = Table.TransformColumns(Result, {"Result", each Text.Combine(List.Transform(_, Text.From)), type text})
in
    Extract[/SIZE]
 
Upvote 0
Here is another UDF (user defined function) that you can consider...
Code:
Function TextOnly(ByVal S As String, Optional LettersOnly As Boolean) As String
  Dim X As Long, Pattern As String
  If LettersOnly Then Pattern = "[!A-Za-z]" Else Pattern = "#"
  For X = 1 To Len(S)
    If Mid(S, X, 1) Like Pattern Then Mid(S, X) = " "
  Next
  TextOnly = Replace(S, " ", "")
End Function
This function has an optional argument that allows you to return all non-numeric characters, punctuation included (omit the second argument or pass in False) or only letters A to Z and a to z (pass in True).

HOW TO INSTALL UDFs
------------------------------------
If you are new to UDFs, they are easy to install and use. To install it, simply press ALT+F11 to go into the VB editor and, once there, click Insert/Module on its menu bar, then copy/paste the above code into the code window that just opened up. That's it.... you are done. You can now use TextOnly just like it was a built-in Excel function. For example,

All non-numeric characters
------------------------------------------
=TextOnly(A1)

or

=TextOnly(A1,FALSE)

Letters Only
------------------------------
=TextOnly(A1,TRUE)

If you are using XL2007 or above, make sure you save your file as an "Excel Macro-Enabled Workbook (*.xlsm) and answer the "do you want to enable macros" question as "yes" or "OK" (depending on the button label for your version of Excel) the next time you open your workbook.
 
Last edited:
Upvote 0
one more (shorter) option with PowerQuery

RawText
A1B2C3D4E5F6G7H8J9K0ABCDEFGHJK
zxc34nbv55qwertyzxcnbvqwerty
AaBb12345CcDdEe678UuRr900AaBbCcDdEeUuRr

Code:
[SIZE=1]// Table1
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    Text = Table.AddColumn(Source, "Text", each Text.Combine(List.RemoveItems(Text.ToList([Raw]),{"0".."9"})))
in
    Text[/SIZE]
 
Upvote 0
Well, 1 more option for formula:

=CONCAT(MID(A1,{1,3,5,7,9,11,13,15,17,19},1))
 
Upvote 0
Here is another UDF

Code:
[/COLOR]Function Subs_s(s As String)
    For i = 0 To 9
        s = Replace(s, i, "")
    Next
    Subs_s = s
End Function
[COLOR=#333333]

Use the udf as shown below

<table border="1" cellspacing="0" style="font-family:Calibri,Arial; font-size:11pt; background-color:#ffffff; "> <colgroup><col style="font-weight:bold; width:30px; " /><col style="width:201.5px;" /><col style="width:163.49px;" /></colgroup><tr style="background-color:#cacaca; text-align:center; font-weight:bold; font-size:8pt; "><td > </td><td >A</td><td >B</td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >1</td><td >A1B2C3D4E5F6G7H8J9K0</td><td >ABCDEFGHJK</td></tr></table><br /><table style="font-family:Arial; font-size:10pt; border-style: groove ;border-color:#00ff00;background-color:#fffcf9; color:#000000; "><tr><td ><b></b></td></tr><tr><td ><table border = "1" cellspacing="0" cellpadding="2" style="font-family:Arial; font-size:9pt;"><tr style="background-color:#cacaca; font-size:10pt;"><td >Cell</td><td >Formula</td></tr><tr><td >B1</td><td >=Subs_s(A1)</td></tr></table></td></tr></table>
 
Upvote 0
Thank you Aryatect, i am currently using Microsoft Office Home and Business 2013, Office 365 will be my next investment very soon.:)
 
Upvote 0

Forum statistics

Threads
1,214,807
Messages
6,121,679
Members
449,047
Latest member
notmrdurden

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