Hafiz, One of our avid readers, writes in.
Dear chandoo,
all the time, I use to spend time exploring chandoo.org. it’s very helpful site. thanks for your day & night efforts.
here I have to face a problem with “Text to Column”. can you please spare some time & guide me.
The problem is when I convert data from text to column using dash “-“, conversion is easy. but when the gap provided in text is with “alt+enter”, i can’t convert the data.
Do you have some solution specifically using text to column.
Well, I tried to use text to columns feature (from Data ribbon) and it would not work.
Although you can use formulas to do the splitting, they might become tedious. So the next logical option is to use macros.
Excel Macros to Split Text on New Lines
So I wrote a simple macro, that would take the text in current cell, split it and place it in adjacent cells. Like this:

Macro Code to split text on new line:
Here is the macro code to split text based on new lines.
Sub splitText()
'splits Text active cell using ALT+10 char as separator
Dim splitVals As Variant
Dim totalVals As Long
splitVals = Split(ActiveCell.Value, Chr(10))
totalVals = UBound(splitVals)
Range(Cells(ActiveCell.Row, ActiveCell.Column + 1), Cells(ActiveCell.Row, ActiveCell.Column + 1 + totalVals)).Value = splitVals
End Sub
How does this code work?
- First we take the activecell’s value and split it based on Chr(10) as delimiter. This is the code for new lines.
- Then, we assign this split values to the range of cells adjacent to active cell.
- Then, we go grab a cup of coffee and sing our favorite song. Because the work is done!
Download Example Workbook
Click here to download example workbook and play with this macro. Make sure to enable macros.
How do you split text?
I really like the built-in text import feature in Excel and use it often. I use it to clean data, remove unnecessary columns or split text. In cases like this, I resort to VBA to have good control over how I want to split.
What about you? How do you split text. What is your experience. Please share your ideas and tips using comments.
Learn more about Splitting Text
If you split often, you will find this tutorial useful.
More VBA & Excel Macro Examples
If you want to learn VBA, go thru these examples













5 Responses to “Preparing Profit / Loss Pivot Reports [Part 2 of 6]”
[...] Preparing Pivot Table P&L using Data sheet [...]
[...] Preparing Pivot Table P&L using Data sheet [...]
[...] Preparing Pivot Table P&L using Data sheet [...]
I am not getting sound from the videos. I have checked all the settings and spent several hours searching the Internet to no avail.
Has anyone else had this problem?
Is there anyway to get the Grand Total to be broken out in the same fashion as the items above it? For instance, if you have in column 1, widget a, widget b, and have their sales by month in column 2, I'd like to see the grand total also be by month, for widget a & b combined.
I can't get anything other than a single line for the grand total, rather than the same format as the data above.
Widget A Month Sales
Jan 100
Feb 200
Widget B
Jan 150
Feb 250
Grand total - here I would also like to have Jan, Feb.
Jan 250
Feb 450