Split text Column to 30 char and not cut word

pwebb

New Member
Joined
Feb 21, 2013
Messages
11
I have textin column B that is 5 to 50 characters long and need to split the text up totwo columns of 30 and not split a word the fun part is that in column B I needto pull out 2 characters to column D and E that are in brackets (AB) first setto D and second to E. Any help will be appreciated <o:p></o:p>
<o:p> </o:p>
Sample ofthe data I am working with<o:p></o:p>
description 1<o:p></o:p>
description 2<o:p></o:p>
Suffix 1<o:p></o:p>
Suffix 2<o:p></o:p>
ROLLER<o:p></o:p>
INSIDE HORIZONTAL VISE FIXED JAW<o:p></o:p>
OUTSIDE HORIZONTAL VISE FIXED JAW<o:p></o:p>
OUTSIDE HORIZONTAL VISE MOVEABLE JAW<o:p></o:p>
SAW BLADE GUIDE PLATE ( DOOR SIDE )<o:p></o:p>
SAW BLADE GUIDE PLATE ( GEAR BOX SIDE )<o:p></o:p>
SAW FLANGE ( P.C.D 63)<o:p></o:p>
CENTER COLLAR (FOR SAW BLADE )<o:p></o:p>
PUMP (ST)(RP)<o:p></o:p>
KNURLED SCREW - OUTSIDE HEAT TREAT<o:p></o:p>
BAR FL 1.00X3.00X1.13 ALUM 6061-T6511<o:p></o:p>
SPR CPRSN (BP)<o:p></o:p>
BARLOADER VERT. ROLLER<o:p></o:p>
<tbody> </tbody>
<o:p> </o:p>
 
...should work assuming there are no bracketed characters preceding the two character sets.
Good point (thanks for mentioning it)... that restriction also applies to the final formulas I posted in Message #9 as well. If you haven't already done so, you might find my formulas of interest as they work directly without resorting to manually applying TextToColumns.
 
Upvote 0

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Yes, thanks for that, Rick. I always find your postings interesting (you're much better at this stuff than I am). Your solution is much more elegant than mine. I just find it a good learning exercise to try and answer this in my own fashion.

Cheers, :)
 
Upvote 0
Rick,<o:p></o:p>
<o:p> </o:p>
Thanks forthe formulas it seem to work only on some cell I have attach an example see red,<o:p></o:p>
B<o:p></o:p>
C<o:p></o:p>
D<o:p></o:p>
E<o:p></o:p>
F<o:p></o:p>
Data<o:p></o:p>
Desc 1<o:p></o:p>
Desc 2<o:p></o:p>
Suf 1<o:p></o:p>
Suf 2<o:p></o:p>
PLATE (RP)<o:p></o:p>
PLATE<o:p></o:p>
(RP)<o:p></o:p>
PLATE<o:p></o:p>
PLATE<o:p></o:p>
PLATE<o:p></o:p>
PLATE<o:p></o:p>
PLATE<o:p></o:p>
PLATE<o:p></o:p>
VISE JAW (RP)<o:p></o:p>
VISE JAW<o:p></o:p>
(RP)<o:p></o:p>
VISE JAW (RP)<o:p></o:p>
VISE JAW<o:p></o:p>
(RP)<o:p></o:p>
SAW FLANGE (RP)<o:p></o:p>
SAW FLANGE<o:p></o:p>
(RP)<o:p></o:p>
CENTER COLLAR (RP)<o:p></o:p>
CENTER COLLAR<o:p></o:p>
(RP)<o:p></o:p>
SAW FLANGE (RP)<o:p></o:p>
SAW FLANGE<o:p></o:p>
SAW FLANGE<o:p></o:p>
(RP)<o:p></o:p>
CENTER COLLAR (RP)<o:p></o:p>
CENTER COLLAR<o:p></o:p>
(RP)<o:p></o:p>
CENTER COLLAR<o:p></o:p>
CENTER COLLAR<o:p></o:p>
BRAKE DISC (RP)<o:p></o:p>
BRAKE DISC<o:p></o:p>
(RP)<o:p></o:p>
<tbody> </tbody>
<o:p> </o:p>
I do have a questioncan the (XX) be just moved to column E and F then the 30 Charter split be doneto C and D also would it be easier to accomplish this with VBA? <o:p></o:p>
<o:p> </o:p>
Thanks againfor all you help<o:p></o:p>
 
Upvote 0
Rick,<o:p></o:p>
<o:p></o:p>
Thanks forthe formulas it seem to work only on some cell I have attach an example see red,<o:p></o:p>

B<o:p></o:p>

C<o:p></o:p>

D<o:p></o:p>

E<o:p></o:p>

F<o:p></o:p>

Data<o:p></o:p>

Desc 1<o:p></o:p>

Desc 2<o:p></o:p>

Suf 1<o:p></o:p>

Suf 2<o:p></o:p>
PLATE (RP)<o:p></o:p>
PLATE<o:p></o:p>
(RP)<o:p></o:p>
PLATE<o:p></o:p>
PLATE<o:p></o:p>
PLATE<o:p></o:p>
PLATE<o:p></o:p>
PLATE<o:p></o:p>
PLATE<o:p></o:p>
VISE JAW (RP)<o:p></o:p>
VISE JAW<o:p></o:p>
(RP)<o:p></o:p>
VISE JAW (RP)<o:p></o:p>
VISE JAW<o:p></o:p>
(RP)<o:p></o:p>
SAW FLANGE (RP)<o:p></o:p>
SAW FLANGE<o:p></o:p>
(RP)<o:p></o:p>
CENTER COLLAR (RP)<o:p></o:p>
CENTER COLLAR<o:p></o:p>
(RP)<o:p></o:p>
SAW FLANGE (RP)<o:p></o:p>
SAW FLANGE<o:p></o:p>
SAW FLANGE<o:p></o:p>
(RP)<o:p></o:p>
CENTER COLLAR (RP)<o:p></o:p>
CENTER COLLAR<o:p></o:p>
(RP)<o:p></o:p>
CENTER COLLAR<o:p></o:p>
CENTER COLLAR<o:p></o:p>
BRAKE DISC (RP)<o:p></o:p>
BRAKE DISC<o:p></o:p>
(RP)<o:p></o:p>

<TBODY>
</TBODY>
<o:p></o:p>
I do have a questioncan the (XX) be just moved to column E and F then the 30 Charter split be doneto C and D also would it be easier to accomplish this with VBA? <o:p></o:p>
<o:p></o:p>
Thanks againfor all you help<o:p></o:p>
When I copy/paste the data you posted and put my formulas into the worksheet, I do not get that anomoly that you posted... the formulas all produce the correct values. The only thing I can think of is there is some kind of "extra" non-visible character in your text, but to tell you the truth, I cannot think of any character off the top of my head would do what you show. You should still have my address... send me the workbook that is doing this and I'll look at it later tonight to see what is going on. I'll also look into giving you a macro that does the split after pulling out the two-character suffixes.
 
Upvote 0
Rick,<o:p></o:p>

Thanks for the quick response; the workbook is 130MB, one thing I did notice that when I post the section of the spreadsheet it is taking out the extra space between the SAW FLANGE and (RP)

It lookslike the issue is an extra space between the SAW and FLANGE that looks like it is the cause

there is two spaces between SAW and FLANGE I remove one and all is good but there are 850000 rows :(
SAW FLANGE (RP)

<tbody>
</tbody>
 
Last edited:
Upvote 0
Rick,

Just wanted to say thanks again for all of your help and expertise, I was able to create a macro from the code you provided.
This is what I came up with and it seems to work, you can let me know if I should have done it differently.

Sub Split_30()
'
' Created on 2/25/2013
'
Columns("C:C").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Columns("C:F").Select
Selection.ColumnWidth = 20
Range("C1").Select
ActiveCell.FormulaR1C1 = "Description 1"
Range("D1").Select
ActiveCell.FormulaR1C1 = "Description 2"
Range("E1").Select
ActiveCell.FormulaR1C1 = "Suffix 1"
Range("F1").Select
ActiveCell.FormulaR1C1 = "Suffix 2"
Columns("C:C").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("C2").Select
ActiveCell.FormulaR1C1 = "=TRIM(RC[-1])"
Selection.AutoFill Destination:=Range("C2:C85634")
Range("C2:C85634").Select
Columns("D:D").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Columns("C:C").Select
Selection.Copy
Columns("D:D").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Columns("C:C").Select
Application.CutCopyMode = False
Selection.Delete Shift:=xlToLeft
Columns("B:B").Select
Selection.Delete Shift:=xlToLeft
Range("C2").Select
ActiveCell.FormulaR1C1 = _
"=TRIM(LEFT(RC[-1],MIN(IF(AND(NOT(ISNUMBER(SEARCH("" (??)*"",RC[-1]))),LEN(RC[-1])<31),LEN(RC[-1]),FIND(""("",RC[-1]&""("")-1),30-LEN(TRIM(RIGHT(SUBSTITUTE(LEFT(RC[-1]&"" "",31),"" "",REPT("" "",99)),99))))))"
Range("D2").Select
ActiveCell.FormulaR1C1 = _
"=TRIM(SUBSTITUTE(IF(LEN(RC[1]&RC[2]),SUBSTITUTE(RC[-2],"" ""&RC[1]&RC[2],""""),RC[-2]),RC[-1],""""))"
Range("E2").Select
ActiveCell.FormulaR1C1 = _
"=IF(ISNUMBER(SEARCH("" (??)*"",RC[-3])),MID(RC[-3],SEARCH("" (??)*"",RC[-3])+1,4),"""")"
Range("E3").Select
ActiveCell.FormulaR1C1 = ""
Range("F2").Select
ActiveCell.FormulaR1C1 = _
"=IF(ISNUMBER(SEARCH("" (??)(??)"",RC[-4])),MID(RC[-4],SEARCH("" (??)(??)"",RC[-4])+5,4),"""")"
Range("C2:F2").Select
Selection.AutoFill Destination:=Range("C2:F85634")
Range("C2:F85634").Select
Columns("G:G").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
ActiveWindow.SmallScroll ToRight:=1
Columns("C:F").Select
Selection.Cut
Columns("C:F").Select
Application.CutCopyMode = False
Selection.Copy
Columns("G:J").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Columns("C:F").Select
Application.CutCopyMode = False
Selection.Delete Shift:=xlToLeft
Columns("B:B").Select
Application.CutCopyMode = False
Selection.Delete Shift:=xlToLeft
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,216,070
Messages
6,128,614
Members
449,460
Latest member
jgharbawi

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