ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Macro for wrapping text (https://www.excelbanter.com/excel-programming/420968-macro-wrapping-text.html)

suestew

Macro for wrapping text
 
I need to wrap text in only those cells where the text won't fit on the
printed page. Here is how I see it.

If the text of a cell extends beyond 15 inches(arbitrary length) (or beyond
Column BD) then wrap it to fit within one cell.



Gary''s Student

Macro for wrapping text
 
If we have rows of standard width, it is easy to determine if the text fits
neatly in that cell or if it "spills over" into its right-most neighbor(s).

For example, say we want to know if the text in A1 fits in A1 or spills
over. We:

1. copy A1 to an un-used row, say A100.
2. store the row height
3. turn on text wrapping for cell A100
4. autofit row 100
5. re-examine the row height

If Excel had to increase the row height, then the text did not fit. This
means that the original text spilled over in A1:

Sub Macro1()
Range("A1").Select
Selection.Copy
Range("A100").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Selection.WrapText = True
Rows("100:100").Select
Selection.Rows.AutoFit
MsgBox (Rows("100:100").Height)
End Sub

Perhaps this shabby little trick can help you.
--
Gary''s Student - gsnu200818


"suestew" wrote:

I need to wrap text in only those cells where the text won't fit on the
printed page. Here is how I see it.

If the text of a cell extends beyond 15 inches(arbitrary length) (or beyond
Column BD) then wrap it to fit within one cell.



JLGWhiz

Macro for wrapping text
 
You have a choice. WrapText will increase the height of a cell to fit the
text in, and AutoFit will increase the width of the cell to fit it in. With
WrapText you can preset the width of the column to have some control over how
man lines actually wrap. You can apply it to a single cell or multiple cells
in a range.
Here is some sample Syntax:
ActiveSheet.Column("B").AutoFit
ActiveSheet.Range("B2").WrapText = True

For more detail refer to the VBA help file in the VB editor.

"suestew" wrote:

I need to wrap text in only those cells where the text won't fit on the
printed page. Here is how I see it.

If the text of a cell extends beyond 15 inches(arbitrary length) (or beyond
Column BD) then wrap it to fit within one cell.




All times are GMT +1. The time now is 06:14 AM.

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