I'm creating a small piece of VBA code with a specific formula, however it has a couple of if
statements, one of which originates a double-line string (with vbNewLine
)
The issue is that I can't see the text.
So I wanted to word wrap it, but each time I set the ActiveCell.WrapText = True
, nothing happens.
I checked with a message box. I set the WrapText
to True, I return the property value with the MessageBox to confirm, and it's still False.
I've been told to use ActiveCell.Rows.AutoFit
as well, but AutoFit
does nothing if the text isn't wrapped.
Any idea what I might be doing wrong here?
Wrap text automatically In a worksheet, select the cells that you want to format. On the Home tab, in the Alignment group, click Wrap Text. (On Excel for desktop, you can also select the cell, and then press Alt + H + W.)
For me, the code below worked. (only set to change header row, (change range))
ActiveSheet.Range("A1:R1").Select
With Selection
.WrapText = True
End With
try:
Sub WrapandFit()
ActiveCell.WrapText = True
ActiveCell.EntireRow.AutoFit
End Sub
It worked for me. Make sure that your screenupdating is also set to true.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With