Generating a excel document

W

Wes

I'm exporting text contained within a HTML table to an Excel file.
The text within a single td tag at times contains the br tag. My
problem is when this data is opened in Excel. I would expect to see a
group of text in a single cell broken up on multiple lines. But what
actually happens is that the br tag in excel actually forces the text
to be in another cell on the next row.

Example:

<td>This is some text<br>that is broken<br>up on multiple lines</td>

when opened in Excel doesn't display in a single cell, it ends up
being in two cells on two rows....

When you have Excel open, the way this is accomplished is by just
entering some text in the cell, then hitting the <Alt>+<Enter>, then
entering more text... but how do I get the equivalent programatically?

Thanks in advance,
Wes
 
W

Wigi

Select you cells to be joined, and run:


Sub joincellsinonecell()

Dim x As Variant
Dim sTemp As String

With Selection

ReDim x(.Rows.Count - 1)

x = .Cells

sTemp = Join(WorksheetFunction.Transpose(x), Chr(10))

.ClearContents

.Cells(1) = sTemp

End With

End Sub


Of course, selecting the cells could be done using other code.
 

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