Auto Row Height

ExcelRoy

Well-known Member
Joined
Oct 2, 2006
Messages
2,540
Office Version
  1. 365
Platform
  1. Windows
Hi Guys,

I have the unfixable problem of needing auto row height to merged cells

I have the following code

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Row = 16 Then
ActiveSheet.Rows(16).AutoFit
End If
End Sub

Which applies the auto row height to row 16, but how would i do the same for rows 16 thru 216

Thanks for any help
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Hi Roy,

It sounds like you are already aware that merged cells can be problematic for VBA and yield unexpected results. Autofit is one example of a function that doesn't work well on merged cells.

That being said, you can modify your code so that it will try to AutoFit Rows 16:216 any time there is a change to a value in Rows 16:216 like this...

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Target, Rows("16:216")) Is Nothing Then
        Rows("16:216").AutoFit
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,506
Messages
6,179,159
Members
452,892
Latest member
yadavagiri

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