Help with this complex macro to remove blank row from autospacing row height?

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
2,592
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. 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
 

Some videos you may like

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).

Watch MrExcel Video

Forum statistics

Threads
1,114,098
Messages
5,545,951
Members
410,713
Latest member
TaremyLunsil
Top