Text To Columns with odd items in brackets

mad3

Board Regular
Joined
Sep 15, 2009
Messages
128
Office Version
  1. 365
Platform
  1. Windows
Hi,

I have two columns with 9 or more single digits numbers that are text. The issue with simple text to columns is that if any of the 9 numbers is a double digit number it looks like this in the cell...

Q​
R​
0001010(11)0400100000
0000001000000000200
101010100000000(10)000


I want to extract each individual number in column Q to separate columns; same with column R. to a separate column to study the totals, but have an issue every time it runs into the odd ball double digit number which is always like this (10)

If it helps, these are line scores from baseball games, but have a number of them with double digit scoring in a single inning.
any ideas on how to extract each number including the double digit numbers?

Thanks, Mike in Cali...
 
Here is another formula that will work...
Excel Formula:
=TEXTSPLIT(TEXTJOIN(" ",,BYROW(WRAPROWS(TEXTSPLIT(Q1&")",{"(",")"}),2,""),LAMBDA(r,TRIM(CONCAT(MID(INDEX(r,1,1),SEQUENCE(99),1)&" ")&INDEX(r,1,2)))))," ")
 
Upvote 0

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Nice catch on that one scenerio with the 22.
have run into a snag in a couple other scenarios. First, if the home team doesn't hit in the bottom of the 9th and it shows an 'x', doesn't work. The other scenario is when there are cells to the columns/cells to the far right of the cell with the formula that are filled, it also fails. I initially cleared out 22 columns, but that was not enough as the formula still did not work. It worked when there were no occupied cells in any of the columns to the right of the formula.
 
Upvote 0
Here is another formula that will work...
Excel Formula:
=TEXTSPLIT(TEXTJOIN(" ",,BYROW(WRAPROWS(TEXTSPLIT(Q1&")",{"(",")"}),2,""),LAMBDA(r,TRIM(CONCAT(MID(INDEX(r,1,1),SEQUENCE(99),1)&" ")&INDEX(r,1,2)))))," ")
Thanks. I am going to give this one a try in a few minutes.
 
Upvote 0
Thanks. I am going to give this one a try in a few minutes.
Post #13 works as long as all columns to the right are empty after the formula cell.. It also has no issue with the 'x' for 9th inning where home team did not bat.
I may just remove all columns to the right after visiting team and split the home team linescore into a separate tble, then rejoin them with power query, if I have no other choice.
 
Upvote 0
Actually, checking again, are you sure?
What about this example?

23 12 02.xlsm
ABCDEFGHIJQSTUVWXYZAAAB
1Using post 5 formulaUsing post 4 formula
211(10)22(11)11(10)11102211111011(10)22(11)11(10)111022111110
To Columns (3)
Cell Formulas
RangeFormula
B2:G2B2=DROP(REDUCE("",TEXTSPLIT(A2,{"(";")"},,1),LAMBDA(a,b,HSTACK(a,IF(LEN(b)=2,b,DROP(TEXTSPLIT(TEXT(b,REPT("0 ",LEN(b)))," "),,-1))))),,1)
S2:AA2S2=LET(ts,TEXTSPLIT(Q2,{"(",")"}),TEXTSPLIT(TEXTJOIN(" ",1,BYCOL(TEXT(SEQUENCE(,COLUMNS(ts)),"00")&ts,LAMBDA(c,IF(ISODD(LEFT(c,2)+0),TEXTJOIN(" ",1,MID(c,SEQUENCE(,99,3),1)),MID(c,3,2)))))," "))
Dynamic array formulas.
Answering post #10: This one has issues with a few different scenarios. If cells are not all empty to right of formula cell, an 'x' in 9th inning or the scenario you showed in that post with the '22'...each of those scenarios did not work. I am thinking I may need to split the data in my table into two separate tables in order so that no cells to the right of the formula have anything in them.
 
Upvote 0
Thanks. I am going to give this one a try in a few minutes.
post #13 second response: I used this formula for scenarios for over 2000 games and it worked for all games for home team. Home team is also in the last active/occupied column on sheet. Only scenario it won't work, the visiting team lines scores where there are cells to the right that are not empty. I made sure I had at least 30 empty cells to the right of visiting team to see if it would work, still no go.
 
Upvote 0
post #13 second response: I used this formula for scenarios for over 2000 games and it worked for all games for home team. Home team is also in the last active/occupied column on sheet. Only scenario it won't work, the visiting team lines scores where there are cells to the right that are not empty. I made sure I had at least 30 empty cells to the right of visiting team to see if it would work, still no go.
Your original file said, "I want to extract each individual number in column Q to separate columns", so I assumed you meant the columns to the right of the data cell. Yes, I know you showed data in Columns Q and R, but gave no instructions what columns you wanted the output to go to. As for the problem with how many cells to the right have to be empty... I think if you change the 99 (inside the SEQUENCE function) to the number of cells you can afford to make clear (but large enough to hold the outputted cells), I believe it will work as you need. For example, for the scenario where you cleared 30 cells, try changing the 99 to 30 (possibly one or two more), I think it should work.
 
Upvote 0
Your original file said, "I want to extract each individual number in column Q to separate columns", so I assumed you meant the columns to the right of the data cell. Yes, I know you showed data in Columns Q and R, but gave no instructions what columns you wanted the output to go to. As for the problem with how many cells to the right have to be empty... I think if you change the 99 (inside the SEQUENCE function) to the number of cells you can afford to make clear (but large enough to hold the outputted cells), I believe it will work as you need. For example, for the scenario where you cleared 30 cells, try changing the 99 to 30 (possibly one or two more), I think it should work.
Yes, you are right. I wanted to extract q and place to the right. What I was amiss about was how many columns I had vacated for the formula to work. My bad. I will follow your suggestion and change sequence to number of vacated columns. Thank you!
 
Upvote 0
Yes, you are right. I wanted to extract q and place to the right. What I was amiss about was how many columns I had vacated for the formula to work. My bad. I will follow your suggestion and change sequence to number of vacated columns. Thank you!
Rick,
What I typically do when someone helps me out with something that is new to me, I review those functions/formulas I have not seen before, and learn how they are used and what each part is doing. Suffice to say, I have not seen or used SEQUENCE function before so I will be reviewing this and others to learn more about them. Thank you so much!
 
Upvote 0
Another option with a recursive lambda function:

TextToColumnsWithOddItemsInBrackets.xlsx
QRSTUVWXYZAA
10001010(11)00001010110
200000010000000001000
310101010001010101000
4400100000400100000
5000000200000000200
600000(10)0000000010000
701234567890123456789
8(10)(11)(12)(13)(14)(15)(16)(17)(18)(19)10111213141516171819
9(20)(21)(22)(23)(24)(25)(26)(27)(28)(29)20212223242526272829
10(30)(31)(32)(33)(34)(35)(36)(37)(38)(39)30313233343536373839
11(40)(41)(42)(43)(44)(45)(46)(47)(48)(49)40414243444546474849
12(50)(51)(52)(53)(54)(55)(56)(57)(58)(59)50515253545556575859
13(60)(61)(62)(63)(64)(65)(66)(67)(68)(69)60616263646566676869
14(70)(71)(72)(73)(74)(75)(76)(77)(78)(79)70717273747576777879
15(80)(81)(82)(83)(84)(85)(86)(87)(88)(89)80818283848586878889
16(90)(91)(92)(93)(94)(95)(96)(97)(98)(99)90919293949596979899
Hoja1
Cell Formulas
RangeFormula
R1:Z1,R7:AA16,R4:Z6,R2:AA3R1=LET(str,myreplace(Q1,10), CODE(MID(str,SEQUENCE(,LEN(str)),1))-48 )
Dynamic array formulas.
Lambda Functions
NameFormula
myreplace=LAMBDA(str,i,IF(i<100,myreplace(SUBSTITUTE(str,"("&i&")",CHAR(48+i)),i+1),str))
 
  • Like
Reactions: JEC
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,849
Members
452,361
Latest member
d3ad3y3

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