Changing Line Feed Behavior

T

TC

I'm preparing an Excel report in which some cells must contain
multiple lines of text. Because of the way Excel handles line feeds,
I'm struggling to format the report properly.
From what I can figure, Excel offers two options:
1) With Wrap Text on, it will break the text at line feeds and
whenever the next word will not fit in the cell.
2) With Wrap Text off, it will never break the text; it will either
ignore line feeds or display them as squares.

What I want is a third option:
3) Break the text at line feeds only (like Notepad does when Word Wrap
is off).

Is there any way to make Excel behave that way?


-TC
 
G

Guest

Make you column width wider than your longest line. then it will only wrap
whre you place your LF.
 
T

TC

Make you column width wider than your longest line. then it will only wrap
whre you place your LF.








- Show quoted text -

Joel,

Thank you for the advice. In fact, I'm already working on that
solution. The problem, of course, is that I'm doing this in code, and
there is no easy way to programmatically determine the length of the
longest line. My kludge is to first make the column width very large,
then auto-size it. That looks like it will work, but isn't a very
elegant solution.

-TC
 
N

NickHK

Whilst there are various API calls available to you for working with, the
need a handle (or rather a device context) to work with, and this is not
readily exposed by Excel/VBA.

An alternative is:
- Split your text on vbLF
- Insert each into a suitably out of the way cell.
- AutoSize. Save the .ColumnWidth if > the previous value.
- Set your desired .ColumnWidth on the above.

NickHK
 

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