ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Add Newline(s) inside a Cell Without Splitting Content into Different Cells (https://www.excelbanter.com/excel-programming/372221-add-newline-s-inside-cell-without-splitting-content-into-different-cells.html)

Emily[_3_]

Add Newline(s) inside a Cell Without Splitting Content into Different Cells
 
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


moon[_6_]

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

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.






"Emily" schreef in bericht
oups.com...
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





All times are GMT +1. The time now is 08:21 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com