Extracting variable amounts of characters from highly variable strings into two columns

bearminmaxing

New Member
Joined
Sep 4, 2024
Messages
3
Office Version
  1. 365
Platform
  1. Windows
I have item IDs that I need to sort, but excel sorts them incorrectly, so I'm trying to extract parts of the IDs to sort them as needed. I've included an example image.

The different item IDs have prefixes that don't change as frequently and often group specifications of items together, then suffixes that change with each individual item. I'd like to separate the prefixes into one column, and the suffixes into another column (ex. ABC12DEF34; prefix ABC12DEF, suffix 34). Because of how many variables I understand if I can't use the same formula across all item IDs, but if possible I'd like to use two formulas only: one formula for the column extracting the prefix and one formula for the column extracting the suffix.
 

Attachments

  • EXAMPLE.png
    EXAMPLE.png
    29.9 KB · Views: 18

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Hello, it is not certain whether the following covers all the possibilities so let us see:

Excel Formula:
=DROP(REDUCE("",A2:A8,LAMBDA(x,y,VSTACK(x,
LET(
array,y,
a,CHAR(SEQUENCE(26,,65)),
b,MAX(IFERROR(SEARCH(a,array),0)),
c,--(MID(array,b+1,LEN(array)-b)),
d,MID(array,1,b),
IFERROR(HSTACK(--(TEXTAFTER(array,"-")),TEXTBEFORE(array,"-")),HSTACK(c,d)))))),1)
 
Upvote 0
So, yesterday I have not considered the possibility that there might be multiple instances of the same letter within one cell which could cause error. The adjusted formula should address it:

Excel Formula:
=DROP(REDUCE("",A1:A2,LAMBDA(x,y,VSTACK(x,
LET(
array,y,
seq,SEQUENCE(LEN(array)),
split,MID(array,seq,1),
a,CHAR(SEQUENCE(26,,65)),
b,MAX(XLOOKUP(a,split,seq,0,,-1)),
c,--(MID(array,b+1,LEN(array)-b)),
d,MID(array,1,b),
IFERROR(HSTACK(--(TEXTAFTER(array,"-")),TEXTBEFORE(array,"-")),HSTACK(c,d)))))),1)
 
Upvote 0
Welcome to the MrExcel board!

I'd like to use two formulas only: one formula for the column extracting the prefix and one formula for the column extracting the suffix.
Is this the sort of thing you are after?

24 09 05.xlsm
ABC
1SuffixPrefix
2123A0000-11123A0000
3123A0000-123123123A0000
4456B1111-2222456B1111
5ABC12DEF11ABC12DEF
6ABC12DEF1010ABC12DEF
7ABC12DEFG123123ABC12DEFG
8ABC34GHJ1234512345ABC34GHJ
Split
Cell Formulas
RangeFormula
B2:B8B2=--TAKE(TEXTSPLIT(SUBSTITUTE(A2,"-","Z"),CHAR(SEQUENCE(,26,65))),,-1)
C2:C8C2=SUBSTITUTE(LEFT(A2,LEN(A2)-LEN(B2)),"-","")
 
Upvote 0
Upvote 0
So, yesterday I have not considered the possibility that there might be multiple instances of the same letter within one cell which could cause error. The adjusted formula should address it:

Excel Formula:
=DROP(REDUCE("",A1:A2,LAMBDA(x,y,VSTACK(x,
LET(
array,y,
seq,SEQUENCE(LEN(array)),
split,MID(array,seq,1),
a,CHAR(SEQUENCE(26,,65)),
b,MAX(XLOOKUP(a,split,seq,0,,-1)),
c,--(MID(array,b+1,LEN(array)-b)),
d,MID(array,1,b),
IFERROR(HSTACK(--(TEXTAFTER(array,"-")),TEXTBEFORE(array,"-")),HSTACK(c,d)))))),1)
Thanks, I appreciate the help! I went ahead and used Peter_SSs's formulas, I unfortunately found it rather difficult to implement this formula, but thank you for taking the time to come up with this solution!
 
Upvote 0
Just for fun another solution:

HighLowDataPoints.xlsx
ABC
1Item NumberSort#SortAZ
2132A0000-11132A0000
3132A0000-123123132A0000
4456B1111-2222456B1111
5ABC12DEF11ABC12DEF
6ABC12DEF1010ABC12DEF
7ABC12DEFG123123ABC12DEFG
8ABC34GHJ1234512345ABC34GHJ
9ABC34GH*1234612346ABC34GH*
10ABC34GH\666666ABC34GH\
11ABC34GH\ ABC34GH\
Sheet2
Cell Formulas
RangeFormula
B2:B11B2=LET(d, A2, l, LEN(d), s, SEQUENCE(,l), i, MAX(s*ISERROR(VALUE(MID(d, s, 1)))), IFERROR(VALUE(MID(d, i+1, l-i)), "") )
C2:C11C2=LET(d, A2, l, LEN(d), s, SEQUENCE(,l), i, MAX(s*ISERROR(VALUE(MID(d, s, 1)))), SUBSTITUTE(MID(d, 1, i), "-","") )


With this formula you can have any non numeric characters and it will take the last number sequence and extract it.
 
Upvote 0

Forum statistics

Threads
1,221,310
Messages
6,159,173
Members
451,543
Latest member
cesymcox

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