jen Rad
asked on
macro to split words to 5 columns
I have a column Title as shown in the attached excel OriginalColumn.
I need to split this column into 5 different columns with max of 35 characters each.
The rules are:
1)Maximum characters allowed in each of these split columns shouldn't exceed 35 characters.
2)The split columns as shown in sample data requiredsplitcolumn shouldn't be cut in middle of a word.
So, basically I need to split the words without cutting them in the middle ...but then for some bigger Titles if split columns exceeds more than 35 characters length it should be cut at a different point (e.g character 32) to reflect a complete word.
This applies to each of the five split columns.
Any ideas how to get my required Final resultset???
OriginalColumn.xlsx
RequiredSplitColumn.xlsx
I need to split this column into 5 different columns with max of 35 characters each.
The rules are:
1)Maximum characters allowed in each of these split columns shouldn't exceed 35 characters.
2)The split columns as shown in sample data requiredsplitcolumn shouldn't be cut in middle of a word.
So, basically I need to split the words without cutting them in the middle ...but then for some bigger Titles if split columns exceeds more than 35 characters length it should be cut at a different point (e.g character 32) to reflect a complete word.
This applies to each of the five split columns.
Any ideas how to get my required Final resultset???
OriginalColumn.xlsx
RequiredSplitColumn.xlsx
How about this?
B3:
=LEFT($A3,FIND("|",SUBSTIT UTE(LEFT($ A3,35)," ","|",LEN(LEFT($A3,35))-LE N(SUBSTITU TE(LEFT($A 3,35)," ",""))))-1)
C3
=TRIM(IF(LEN($A3)-LEN($B3) -1<35,MID( $A3,LEN($B 3)+1,36),L EFT(MID($A 3,LEN($B3) +1,LEN($A3 )),FIND("| ",SUBSTITU TE(LEFT(MI D($A3,LEN( $B3)+1,LEN ($A3)),35) ," ","|",LEN(LEFT(MID($A3,LEN ($B3)+1,LE N($A3)),35 ))-LEN(SUB STITUTE(LE FT(MID($A3 ,LEN($B3)+ 1,LEN($A3) ),35)," ",""))))-1)))
D3
=TRIM(IF(LEN($A3)-(LEN($B3 )+LEN($C3) +1)-1<35,M ID($A3,(LE N($B3)+LEN ($C3)+1)+1 ,36),LEFT( MID($A3,(L EN($B3)+LE N($C3)+1)+ 1,LEN($A3) ),FIND("|" ,SUBSTITUT E(LEFT(MID ($A3,(LEN( $B3)+LEN($ C3)+1)+1,L EN($A3)),3 5)," ","|",LEN(LEFT(MID($A3,(LE N($B3)+LEN ($C3)+1)+1 ,LEN($A3)) ,35))-LEN( SUBSTITUTE (LEFT(MID( $A3,(LEN($ B3)+LEN($C 3)+1)+1,LE N($A3)),35 )," ",""))))-1)))
E3
=TRIM(IF(LEN($A3)-(LEN($B3 )+LEN($C3) +LEN($D3)+ 2)-1<35,MI D($A3,(LEN ($B3)+LEN( $C3)+LEN($ D3)+2)+1,3 6),LEFT(MI D($A3,(LEN ($B3)+LEN( $C3)+LEN($ D3)+2)+1,L EN($A3)),F IND("|",SU BSTITUTE(L EFT(MID($A 3,(LEN($B3 )+LEN($C3) +LEN($D3)+ 2)+1,LEN($ A3)),35)," ","|",LEN(LEFT(MID($A3,(LE N($B3)+LEN ($C3)+LEN( $D3)+2)+1, LEN($A3)), 35))-LEN(S UBSTITUTE( LEFT(MID($ A3,(LEN($B 3)+LEN($C3 )+LEN($D3) +2)+1,LEN( $A3)),35), " ",""))))-1)))
B3:
=LEFT($A3,FIND("|",SUBSTIT
C3
=TRIM(IF(LEN($A3)-LEN($B3)
D3
=TRIM(IF(LEN($A3)-(LEN($B3
E3
=TRIM(IF(LEN($A3)-(LEN($B3
ASKER
This is Perfect...Thanks nutsch!
Will test it with my data & get back to you shortly!
Thanks very Much!
Will test it with my data & get back to you shortly!
Thanks very Much!
ASKER
Hi nutsch... I have a quick question. I see that the above formula splits the Title to another column even if the length of the word is less than the 35 characters.
for Example...I have this sample Titles like shown below which are less than 35 characters...it is being split to different column? Can we just leave them in their cell if they the title length <35 in the same cell???
Sample titles that has length <35 but gets split to another column:
__________________________ __________ __________ __________ __________ _____
David Cohn
Jon Milek
Mark Geth
Rick Hills
Rob Bale
Thanks very much!
for Example...I have this sample Titles like shown below which are less than 35 characters...it is being split to different column? Can we just leave them in their cell if they the title length <35 in the same cell???
Sample titles that has length <35 but gets split to another column:
__________________________
David Cohn
Jon Milek
Mark Geth
Rick Hills
Rob Bale
Thanks very much!
edit B3 formula to:
=IF(LEN($A3)<36,$A3,LEFT($ A3,FIND("| ",SUBSTITU TE(LEFT($A 3,35)," ","|",LEN(LEFT($A3,35))-LE N(SUBSTITU TE(LEFT($A 3,35)," ",""))))-1))
=IF(LEN($A3)<36,$A3,LEFT($
ASKER
Thank you so very Much!
It works amazingly well & exactly what I wanted:)...Just a few things I happened to notice...
I have attached the sample data excel for your reference.
For this sample data shown I am getting a little glitch in the splitcolumn Title_3. Any ideas???
If I could get a fix for this , it would really help:)
Also, I will need a formula for splitcolumn Title_5 as these Titles are sometimes are really big and might extend until Title_5.
I know the data I am working with is totally unstructured data:(.But I cannot alter anything on this data as it has some important details. So had to deal with this data as is as I have no other choice:(...my bad!
Thanks very much for helping!!!
SplitColumn-test2.xlsx
It works amazingly well & exactly what I wanted:)...Just a few things I happened to notice...
I have attached the sample data excel for your reference.
For this sample data shown I am getting a little glitch in the splitcolumn Title_3. Any ideas???
If I could get a fix for this , it would really help:)
Also, I will need a formula for splitcolumn Title_5 as these Titles are sometimes are really big and might extend until Title_5.
I know the data I am working with is totally unstructured data:(.But I cannot alter anything on this data as it has some important details. So had to deal with this data as is as I have no other choice:(...my bad!
Thanks very much for helping!!!
SplitColumn-test2.xlsx
in D2
=TRIM(IF(LEN($A2)-(LEN($B2 )+LEN($C2) +1)-1<35,I F(LEN(B2)+ LEN(C2)+1= LEN(TRIM($ A2)),"",MI D($A2,(LEN ($B2)+LEN( $C2)+1)+1, 36)),LEFT( MID($A2,(L EN($B2)+LE N($C2)+1)+ 1,LEN($A2) ),FIND("|" ,SUBSTITUT E(LEFT(MID ($A2,(LEN( $B2)+LEN($ C2)+1)+1,L EN($A2)),3 5)," ","|",LEN(LEFT(MID($A2,(LE N($B2)+LEN ($C2)+1)+1 ,LEN($A2)) ,35))-LEN( SUBSTITUTE (LEFT(MID( $A2,(LEN($ B2)+LEN($C 2)+1)+1,LE N($A2)),35 )," ",""))))-1)))
=TRIM(IF(LEN($A2)-(LEN($B2
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Nutsch...Thank you very much. Sure, I Will also try your above solution & let you know.
In the meantime, I was just testing my crappy data...and I came across few things. Maybe if you could review it
Attached is the file for your reference.
Thank you soo very much!!!...you are really great:)
SplitColumn-test3.xlsx
FewFixes.jpg
In the meantime, I was just testing my crappy data...and I came across few things. Maybe if you could review it
Attached is the file for your reference.
Thank you soo very much!!!...you are really great:)
SplitColumn-test3.xlsx
FewFixes.jpg
ASKER
Hi Nutsch...a quick question. Am sorry am not very familiar with the excel and relatively new to this.
After I added the above code to the new module & I trying to get this to run using Ctrl+F8. what am I missing? It doesn't show up with the name of the macro for me to choose to run. Any ideas??
I have attached the files and the screenshot ...for your reference.
Can you please provide me the step to step instructions to get this work on the excel?
Thank you very much...Nutsch!
RunMacroScreen1.jpg
AddedFormulaToB2Cell.jpg
SplitColumn-macrotest1.xlsm
After I added the above code to the new module & I trying to get this to run using Ctrl+F8. what am I missing? It doesn't show up with the name of the macro for me to choose to run. Any ideas??
I have attached the files and the screenshot ...for your reference.
Can you please provide me the step to step instructions to get this work on the excel?
Thank you very much...Nutsch!
RunMacroScreen1.jpg
AddedFormulaToB2Cell.jpg
SplitColumn-macrotest1.xlsm
It's not a macro, it's a user defined function (udf). You copy it in a module like a macro, but you call it in a cell like other functions. In this case, write in cell b2
=get35chars($a2:a2)
=get35chars($a2:a2)
ASKER
Copy / paste
ASKER
so should I copy /paste the same to the other four cells??
=get35chars($a2:a2)
=get35chars($a2:a2)
ASKER
ok...now I got it!...
ASKER
Excellent!...Thank you sooo much:)
ASKER
Brilliant!
The problem being is that your data is unstructured