Add Newline(s) inside a Cell Without Splitting Content into Different Cells

E

Emily

Hi All,

I'm writing output to an Excel file. I have to write all of the
differences into a single cell. Now I've got an output that looks like
this (in a single cell):

The number of text objects differ on page 1: 12; 10 | The number of
text objects differ on page 1: 17; 15 | The number of text objects
differ on page 1: 17; 15 | The number of text objects differ on page 1:
16; 14 | The number of text objects differ on page 1: 17; 15 | The
number of text objects differ on page 1: 18; 16 |

As you can see, it's humanly readable. I want to make it look like
following:

The number of text objects differ on page 1: 12, 10
The number of text objects differ on page 1: 17, 15
The number of text objects differ on page 1: 17, 15
The number of text objects differ on page 1: 16, 14
The number of text objects differ on page 1: 17, 15
The number of text objects differ on page 1: 18, 16

I don't know how to make it look like this. Because, if I add a a
newline ("\r\n") after each difference, this will be split into 6
separate lines - They won't be in the same cell anymore. Any advice?

Thanks!
-Emily
 
M

moon

This is 'a' macro. It dumps the output in Sheet2, Cells A1, A2, A3, A4, etc.


Public Sub splitter()
Dim wb As Workbook, ws As Worksheet
Dim f, b, i As Integer
Dim sInput, sResult As String
Set wb = ThisWorkbook
Set ws = wb.Sheets("Sheet2")
ws.Activate
f = 1: b = 1
sResult = vbNullString
sInput = "The number of text objects differ on page 1: 12; 10 | The
number of text objects differ on page 1: 17; 15 | The number of text objects
differ on page 1: 17; 15 | The number of text objects differ on page 1: 16;
14 | The number of text objects differ on page 1: 17; 15 | The number of
text objects differ on page 1: 18; 16 |"
ws.Cells(f, b).Select
For i = 1 To Len(sInput) Step 1
If Asc(Mid(sInput, i, 1)) <> 124 Then
sResult = sResult & Mid(sInput, i, 1)
Else
sResult = LTrim(Left(sResult, Len(sResult) - 1))
ws.Cells(f, b).Value = sResult
sResult = vbNullString
f = f + 1
End If
Next i
End Sub


It's up to you to implement this, because from here I cannot see what your
workbook looks like.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top