Helloguys
Helloguys

Reputation: 289

Excel line break vs VBA line break?

I'm writing VBA codes to read spreadsheet contents and write to a TXT file.

Some of the cells has multi-line text. They are displayed as multi-line in the spreadsheet.

However, when the VBA code read the cell and write to the TXT file, they appear on the same line. This also happens when I copy the cell and past it into Notepad.

For example in spreadsheet, cell A1 appears as:

Text1
Text2
Text3

But in TXT file, it appears as: Text1Text2Text3.

So I guess CHAR(10) in Excel is not equivalent to vbNewLine in VBA? What do I need to do to get the line breaks into TXT file? Thank you!

Upvotes: 0

Views: 249

Answers (2)

Marion Gordon
Marion Gordon

Reputation: 1

I had the same problem, and resolved it by changing my column to word wrap. Please be gentle if this is a silly solution - this is my first answer on the forum. :-)

Upvotes: 0

Sam
Sam

Reputation: 5721

Do a Replace(YourCellValue, vbLf, vbCrLf) to get line breaks that works in Windows.

Upvotes: 0

Related Questions