VBA to break text in single cell into parts given a delimiter

rsulliva

Board Regular
Joined
Sep 13, 2007
Messages
131
Office Version
  1. 365
Platform
  1. Windows
I would like to run a macro that will break a single cell into many cells in a column of data. Example: Cell A1 contains the text "text1 & text2 & text3 & text4". Actually, there are hundreds of texts with "&" in between within this cell. I would like the macro to be able to break this text into B1:B4 as follows. B1: text1; B2: text2; B3: text3; B4: text4; etc.

How can this be done using a Macro? Thank you.
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Do you really need a macro as this is readily achieved with a formula?

rsulliva.xlsm
AB
1text1 & text2 & text3 & text4text1
2text2
3text3
4text4
5
Sheet1
Cell Formulas
RangeFormula
B1:B4B1=TRIM(TEXTSPLIT(A1,,"&"))
Dynamic array formulas.


If you must have vba then you could use the same idea only with vba

VBA Code:
Sub Break_Text()
  With Range("B1")
    .Formula2 = "=trim(textsplit(A1,, ""&""))"
    .SpillingToRange.Value = .SpillingToRange.Value
  End With
End Sub
 
Upvote 0
Solution
Hey Peter_SSs, your solutions worked great. I didn't know the formula even existed. Great to know! Thanks
 
Upvote 0
You're welcome. Thanks for the follow-up. :)
 
Upvote 0

Forum statistics

Threads
1,221,310
Messages
6,159,176
Members
451,543
Latest member
cesymcox

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