separate numbers from text

lezawang

Well-known Member
Joined
Mar 27, 2016
Messages
1,805
Office Version
  1. 2016
Platform
  1. Windows
Hi
is it possible to separate text from number if the test is like this

12344AAAAAAAAA12333333AAAAAAA

or

BBBBBBB12344BBB123BBBBBBB211BBBBB122

in summery text and number together, no space, no - or , or tab etc.

Thanks
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
What is the result that you are looking to get from the data that you posted?

If you have 12344AAAAAAAAA12333333AAAAAAA, are you looking to get something like 1234412333333AAAAAAAAAAAAAAAA?
 
Upvote 0
Thanks, yes that is one or just put the text in one column and the number in another column.
 
Upvote 0
If you have Excel 2016 then you can use this:


Excel 2016
ABC
112344AAAAAAAAA12333333AAAAAAA1234412333333AAAAAAAAAAAAAAAA
2BBBBBBB12344BBB123BBBBBBB211BBBBB12212344123211122BBBBBBBBBBBBBBBBBBBBBB
Sheet17
Cell Formulas
RangeFormula
B1{=TEXTJOIN("",,IFERROR((MID(A1,ROW(INDIRECT("1:"&LEN(A1))),1)/10)*10,""))}
C1{=TEXTJOIN("",,IF(ISNUMBER(MATCH(CODE(MID(A1,ROW(INDIRECT("1:"&LEN(A1))),1)),ROW(INDIRECT("65:90")),0)),MID(A1,ROW(INDIRECT("1:"&LEN(A1))),1),""))}
Press CTRL+SHIFT+ENTER to enter array formulas.
 
Last edited:
Upvote 0
If you don't have the TextJoin function available, here is some code that will do the trick. This assumes that your data is in column A starting in A1. I commented the code with an alternative that allows you to just select the range manually. This will output the results in the 2 columns to the right of your original column. Let me know if you have any questions.

Code:
Sub SeparateAlphaNum()
Dim r As Range
Dim AR()
Dim res()
Dim tmp As String
Dim num As String
Dim alpha As String


Set r = Range("A1:A" & Range("A" & Rows.Count).End(xlUp).Row()) 'Change references to where your data is
'set r = application.InputBox("Select Range","Excel",,,,,,8) 'You can use this to select the range manually
AR = r.Value
ReDim res(1 To UBound(AR), 1 To 2)


For i = 1 To UBound(AR)
    For j = 1 To Len(AR(i, 1))
        tmp = Mid(AR(i, 1), j, 1)
        If IsNumeric(tmp) Then
            num = num & tmp
        Else
            alpha = alpha & tmp
        End If
    Next j
    res(i, 1) = "'" & num
    res(i, 2) = alpha
    tmp = vbNullString
    alpha = vbNullString
    num = vbNullString
Next i


Set r = r.Cells(1, 1).Offset(, 1)
Set r = r.Resize(UBound(res), UBound(res, 2))
r.Value = res()


End Sub
 
Upvote 0
Or... Here are two functions that you can use to do the same thing.

Code:
Function SeparateNum(s As String) As String
Dim num As String
Dim n As String
For i = 1 To Len(s)
    n = Mid(s, i, 1)
    If IsNumeric(n) Then
        num = num & n
    End If
Next i
SeparateNum = num
End Function


Function SeparateAlpha(s As String) As String
Dim alpha As String
Dim n As String
For i = 1 To Len(s)
    n = Mid(s, i, 1)
    If Not IsNumeric(n) Then
        alpha = alpha & n
    End If
Next i
SeparateAlpha = alpha
End Function

After pasting the code, in your worksheet you would use the functions like, =SeparateNum(A1) and =SeparateAlpha(A1).
 
Upvote 0

Forum statistics

Threads
1,224,825
Messages
6,181,191
Members
453,021
Latest member
pingpong7117

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