tonywatsonhelp
Well-known Member
- Joined
- Feb 24, 2014
- Messages
- 3,210
- Office Version
- 365
- 2019
- 2016
- Platform
- Windows
Hi Everyone,
I have a macro that is designed to auto adjust the row height of each row in a range to fit the amount of text in that cell.
It works quite well but the problem is i get times when it leaves an empty row.
so for example if its adjusting text that should take up two rows in height so about 30 row height, it will do 45?
I cant figure out why or how to stop it?
it only happens once in a while but is very frustating
I have the macro because my text is inserted into merged cells and the autofit does not work on merged cells,
if anyone can let me know how i can deal with this it would be very helpful.
or if someone could add a check to the code that says for each line of code in cells rowheight should = 15? this would do the job.
any help would be apreciated
here my code
Sub Invi_activatesetup()
Application.EnableEvents = False
Application.ScreenUpdating = False
For I = 91 To 112
On Error Resume Next
If Range("E" & I).Value = 0 Then
Range("E" & I).RowHeight = 15
Else
With Range("E" & I & ":H" & I)
If .MergeCells And .WrapText Then
Set c = Range("E" & I).Cells(1, 1)
cWdth = c.ColumnWidth
Set ma = c.MergeArea
For Each cc In ma.Cells
MrgeWdth = MrgeWdth + cc.ColumnWidth
Next
ma.MergeCells = False
c.ColumnWidth = MrgeWdth
c.EntireRow.AutoFit
NewRwHt = c.RowHeight
If NewRwHt < 15 Then
NewRwHt = 15
End If
c.ColumnWidth = cWdth
ma.MergeCells = True
ma.RowHeight = NewRwHt
cWdth = 0: MrgeWdth = 0
End If
End With
End If
Next I
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub
thanks
Tony
I have a macro that is designed to auto adjust the row height of each row in a range to fit the amount of text in that cell.
It works quite well but the problem is i get times when it leaves an empty row.
so for example if its adjusting text that should take up two rows in height so about 30 row height, it will do 45?
I cant figure out why or how to stop it?
it only happens once in a while but is very frustating
I have the macro because my text is inserted into merged cells and the autofit does not work on merged cells,
if anyone can let me know how i can deal with this it would be very helpful.
or if someone could add a check to the code that says for each line of code in cells rowheight should = 15? this would do the job.
any help would be apreciated
here my code
Sub Invi_activatesetup()
Application.EnableEvents = False
Application.ScreenUpdating = False
For I = 91 To 112
On Error Resume Next
If Range("E" & I).Value = 0 Then
Range("E" & I).RowHeight = 15
Else
With Range("E" & I & ":H" & I)
If .MergeCells And .WrapText Then
Set c = Range("E" & I).Cells(1, 1)
cWdth = c.ColumnWidth
Set ma = c.MergeArea
For Each cc In ma.Cells
MrgeWdth = MrgeWdth + cc.ColumnWidth
Next
ma.MergeCells = False
c.ColumnWidth = MrgeWdth
c.EntireRow.AutoFit
NewRwHt = c.RowHeight
If NewRwHt < 15 Then
NewRwHt = 15
End If
c.ColumnWidth = cWdth
ma.MergeCells = True
ma.RowHeight = NewRwHt
cWdth = 0: MrgeWdth = 0
End If
End With
End If
Next I
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub
thanks
Tony