Splitting an alpha numeric string

ECB

Board Regular
Joined
Mar 3, 2009
Messages
60
Office Version
  1. 365
Platform
  1. MacOS
  2. Mobile
Hi there,

Regards to all, and I hope you are all staying safe in these mad times.

I have a question about splitting an alphanumeric string that I think I've got clear in my head, I know there will be a simple solution, but I just can't grasp it.

I have an alphanumeric string which consists of one/two letters, following by one/two numbers sometimes followed by a space, followed by a single number followed by two letters.

That is the string could be any of the following:

G2 1AA (which might also be written as G21AA)
G32 1AA (which might also be written as G321AA)
GA2 1AA (which might also be written as GA21AA)
GA32 1AA (which might also be written as GA321AA)

Now I want to split the first part (the single or double letter, and the single or double number) from the second part which is always a single number followed by two letters. I'd like a formula that works for all combinations of the string.

I might have overthought this, as actually all I want to do is take the last 3 letters of the string for the second part, and trim the last 3 letters for the first part - the trim function would strip out spaces.

Am I right?
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
I wish I'd come here ages ago, as just typing it out I think I've got it.

If A1 is the cell with the string then:

=TRIM(LEFT(A1,LEN(A1)-3)) for first bit and

=RIGHT(A1,3)

for second bit.

Thanks for reading, and the inspiration!
 
Upvote 0
Using Power Query, here is the Mcode. A simple split based upon the three right places.

VBA Code:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Split Column by Position" = Table.SplitColumn(Source, "Column1", Splitter.SplitTextByPositions({0, 3}, true), {"Column1.1", "Column1.2"})
in
    #"Split Column by Position"

Book1
AB
1Column1.1Column1.2
2G21AA
3G321AA
4GA21AA
5GA321AA
Sheet2
 
  • Like
Reactions: ECB
Upvote 0
Thanks for the responses - much appreciated. This is the best forum on tinternet.
 
Upvote 0
Glad we could help & thanks for the feedback
 
  • Like
Reactions: ECB
Upvote 0

Forum statistics

Threads
1,215,506
Messages
6,125,193
Members
449,213
Latest member
Kirbito

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