SEPARATING ALPHANUMERIC DATA WHEN PATTERN IS IRREGULAR

tyronemeister

New Member
Joined
Jun 30, 2006
Messages
28
Is there a way to automatically separate numbers and letters in cells when the number of letters and/or numbers varies, preferably with vba? That is, separate them to different columns.

There's no delimiter and the width is not fixed, so the text to columns feature is not useful without sorting the information first. Apparently, isnumber cannot be used to because numbers are recognized as text when concatenated with letters.

Here's an example of what I want to do:

Before separating the data:

12ABB
1ABB
12AB

After separating:

Code:
Col1    Col2

12       ABB
1        ABB
12       AB

Thanks.
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,304
Office Version
  1. 365
Platform
  1. Windows
Are the numbers always at the start?
Code:
Sub Seperate()
    For Each c In Range("A1:A10")
    
        c.Offset(, 1) = Val(c.Value)
        c.Offset(, 2) = Mid(c.Value, Len(c.Offset(, 1)) + 1)
        
    Next c
End Sub
 

Greg Truby

MrExcel MVP
Joined
Jun 19, 2002
Messages
10,019
<ul>[*]=regexpsubstitute(A1,"[A-Z a-z]","")[*]=regexpsubstitute(A1,"[0-9]","")[/list] Where the function regexpsubstitute is taken from Tushar's site.
 

Greg Truby

MrExcel MVP
Joined
Jun 19, 2002
Messages
10,019
Yes, but you may wish to make note of the difference in output should the input ever stray from the format you describe. Compare the results of each when inputs are things like<ul>[*]1AB2DE3[*]123ABC123[*]GHI789[*]XYZ[*]123[/list]I cannot speculate as to which solution would yield more desireable results for you (or indeed perhaps neither would). But I would think that from your POV it would be worth noting.
 

Forum statistics

Threads
1,141,937
Messages
5,709,430
Members
421,636
Latest member
kelseyacheson

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
Top