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

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
3,210
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
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result

Forum statistics

Threads
1,223,236
Messages
6,170,917
Members
452,366
Latest member
TePunaBloke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top