DRSteele

Split text cell into columns of words.

DRSteele

Well-known Member
Joined
Mar 31, 2015
Messages
2,640
Office Version
  1. 365
Platform
  1. Windows
DRSteele submitted a new Excel article:

Split text cell into columns of words. - Using Excel's new dynamic array formulas, we can easily Split text cell into columns of words.

If you have a cell containing a text string with spaces in it and you want to split it by spaces into columns, you can easily do so by using the Text-to-Columns functionality. Or you can use Power Query to clean up and split everything.

Or if you want to use formulas, this algorithm can help. Here we see the old way is a bit cumbersome and requires a set of columns with the anticipated number of words and hence requires user action to copy the formulas to the right. But the new dynamic...

Read more about this Excel article...
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Great article, @DRSteele!

I'd like to make a contribution to this concept.
I am impressed with Dynamic Array formulas every day. It even works with user defined functions.

I created this one liner as a function that simply returns an array with Split internal function:

VBA Code:
Function splitText(rng As Range)
    splitText = Split(rng, " ")
End Function
Here is the result by using the same range as input:
SplitText.xlsm
ABCDEFGHIJKLMNOP
1Wall panels for interior wall.Wallpanelsforinteriorwall.
2This a test.Thisatest.
3This too is a test.Thistooisatest.
4This has too many spaces for the Word Number maxtrix, but is ok here.ThishastoomanyspacesfortheWordNumbermaxtrix,butisokhere.
5Notice how the punctation follows the word! Right?Noticehowthepunctationfollowstheword!Right?
6…unless, of course, there is a space , like here .…unless,ofcourse,thereisaspace,likehere.
Sheet1
Cell Formulas
RangeFormula
C1:G1,C6:M6,C5:J5,C4:P4,C3:G3,C2:E2C1=splitText(A1)
Dynamic array formulas.
 
Thanks for the supplement, Smozgur!
 
Using Excel's new dynamic array formulas, we can easily Split text cell into columns of words.
Hi Don

Two quite minor observations regarding your formula
=TRIM(MID(SUBSTITUTE($B13," ",REPT(" ",LEN($B13))),SEQUENCE(1,LEN(B13)-LEN(SUBSTITUTE(B13," ",""))+1,0)*LEN($B13)+1,LEN($B13)))
  1. In relation to B13, you have used some absolute column references and some not. None are needed so for uniformity all the $ signs could be removed.
  2. You could also make use of the STEP argument of SEQUENCE to remove the need for the multiplication.
=TRIM(MID(SUBSTITUTE(B13," ",REPT(" ",LEN(B13))),SEQUENCE(1,LEN(B13)-LEN(SUBSTITUTE(B13," ",""))+1,1,LEN(B13)),LEN(B13)))
 
Peter, your observations and suggestions are once again very valuable. I will change the article to reflect your improvements.

Thanks, Peter!
 
Thanks, Peter!
You're welcome. You are doing all the hard work. :)


I created this one liner as a function
Another very minor point. Since space is the default delimiter for Split, and you have assumed default settings for the other optional arguments, the one-liner could become

VBA Code:
Function splitText(rng As Range)
    splitText = Split(rng)
End Function
 
Since space is the default delimiter for Split

There is no single day that I don't learn something new! I probably used Split function 20+ years ago, and I just learned the space is the default delimiter in VBA.
Thanks, Peter!
 

Forum statistics

Threads
1,216,503
Messages
6,131,022
Members
449,616
Latest member
PsychoCube

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