Extracting words from a cell

andreascostas

Board Regular
Joined
Jan 11, 2011
Messages
150
I have a list of words in cell A1, the words are separated by commas. Sometimes the list is one word and other times it
has as many as fifty words in it. I need to separate each word in its own cell without the commas. So continuing on the same row
B1, C1, D1 etc. Is there a function I can drag across the rows and get each word by itself?
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Hi andreascostas,

Not sure about a native Excel function to do what you're after but this macro will:

VBA Code:
Option Explicit
Sub Macro1()

    Dim strData() As String
    Dim i As Long
    
    Application.ScreenUpdating = False
    
    strData = Split(Range("A1"), ",")
    
    For i = LBound(strData) To UBound(strData)
        Range("A1").Offset(0, i + 1).Value = strData(i)
    Next i
    
    Application.ScreenUpdating = True

End Sub

Regards,

Robert
 
Upvote 0
Option Explicit Sub Macro1() Dim strData() As String Dim i As Long Application.ScreenUpdating = False strData = Split(Range("A1"), ",") For i = LBound(strData) To UBound(strData) Range("A1").Offset(0, i + 1).Value = strData(i) Next i Application.ScreenUpdating = True End Sub
Awesome, Thank you. It works perfectly.
 
Upvote 0
You can also do this with a non-looping macro as well...
VBA Code:
Sub Macro1()
  Dim Arr() As String
  Arr = Split(Range("A1"), ",")
  Range("B1").Resize(1, 1 + UBound(Arr)) = Arr
End Sub
 
Upvote 0
another way
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    MaxCount = List.Max(Table.AddColumn(Source, "SCount", each List.Count(Text.Split([raw],",")))[SCount]),
    Split = Table.SplitColumn(Source, "raw", Splitter.SplitTextByDelimiter(","), MaxCount)
in
    Split
eg.
rawraw.1raw.2raw.3raw.4
a,b,cabc
d,rdr
qwer,opt,hjk,lopqweropthjklop
 
Upvote 0
You can also quickly do it manually with Text to Columns (on the Data ribbon tab) by selecting the cell (or column) choosing Delimited -> Next -> Comma only -> Next -> Destination: B1 -> Finish

Or same thing as a one-liner macro
VBA Code:
Sub TtC()
    Columns("A").TextToColumns Range("B1"), xlDelimited, , , False, False, True, False, False
End Sub

If you have other data in column A and you really do only want to do this for A1 as described in post 1 then Change Columns("A") to Range("A1") in the above code


Or to answer the question you actually asked ..
Is there a function I can drag across the rows and get each word by itself?
.. Yes, but the formula suggested would depend on your Excel version. So I suggest that you update your Account details (click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using. (Don’t forget to scroll down & ‘Save’)
 
Upvote 0
Data is in A1. Put this formula in B1

=TRIM(MID(SUBSTITUTE(A1,",",REPT(" ",100)),SEQUENCE(,LEN(A1)-LEN(SUBSTITUTE(A1,",",""))+1,0)*100+1,100))
 
Upvote 0
Data is in A1. Put this formula in B1

=TRIM(MID(SUBSTITUTE(A1,",",REPT(" ",100)),SEQUENCE(,LEN(A1)-LEN(SUBSTITUTE(A1,",",""))+1,0)*100+1,100))
Hi John, hope you are well!!

Firstly, clarifying for readers that this formula would require excel 365.

But also note that the OP states up to 50 words in the cell so your substitution of 100 spaces will not be sufficient - see cells T1:U1 below.
To be sure, we need to insert at least as many spaces as the length of the original string as shown in row 2, or similar in row 3 but shortening the formula a little in both length & calculation time by using the LET function if available.

20 12 28.xlsm
ABCDEFGHIJKLMNOPQRSTUV
1one,two,three,four,five,six,seven,eight,nine,ten,eleven,twelve,thirteen,fourteen,fifteen,sixteen,seventeen,eighteen,nineteen,twentyonetwothreefourfivesixseveneightnineteneleventwelvethirteenfourteenfifteensixteenseventeeneighteennineteen
2one,two,three,four,five,six,seven,eight,nine,ten,eleven,twelve,thirteen,fourteen,fifteen,sixteen,seventeen,eighteen,nineteen,twentyonetwothreefourfivesixseveneightnineteneleventwelvethirteenfourteenfifteensixteenseventeeneighteennineteentwenty
3one,two,three,four,five,six,seven,eight,nine,ten,eleven,twelve,thirteen,fourteen,fifteen,sixteen,seventeen,eighteen,nineteen,twentyonetwothreefourfivesixseveneightnineteneleventwelvethirteenfourteenfifteensixteenseventeeneighteennineteentwenty
Split Words
Cell Formulas
RangeFormula
B1:U1B1=TRIM(MID(SUBSTITUTE(A1,",",REPT(" ",100)),SEQUENCE(,LEN(A1)-LEN(SUBSTITUTE(A1,",",""))+1,0)*100+1,100))
B2:U2B2=TRIM(MID(SUBSTITUTE(A2,",",REPT(" ",LEN(A2))),SEQUENCE(,LEN(A2)-LEN(SUBSTITUTE(A2,",",""))+1,0)*LEN(A2)+1,LEN(A2)))
B3:U3B3=LET(L,LEN(A3),TRIM(MID(SUBSTITUTE(A3,",",REPT(" ",L)),SEQUENCE(,L-LEN(SUBSTITUTE(A3,",",""))+1,0)*L+1,L)))
Dynamic array formulas.
 
Upvote 0
Hello Pete,
Hope you are well too. It has been a while.

Sorry for not clarifying to detail. I missed out the 50 words requirement.
Thanks for the wonderful tip with your alternatives. They are great!!! :)
 
Upvote 0

Forum statistics

Threads
1,215,477
Messages
6,125,037
Members
449,205
Latest member
Eggy66

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