VBA to Autofit Row Height on SheetChange

sbrien

New Member
Joined
Jun 5, 2012
Messages
19
Hello,

My problem is that even though I set my sheet to Autofit row height, it doesn't recognize the full text in the cell because the cells only contain references to text on other sheets. I'd like it to autofit every time I make a change or every time I change sheets.

I found the following code elsewhere online, but it's not working for some reason.

Code:
[COLOR=#333333]Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)[/COLOR]
[COLOR=#333333]  Dim WS As Worksheet[/COLOR]
[COLOR=#333333]  For Each WS In ThisWorkbook.Worksheets[/COLOR]
[COLOR=#333333]    WS.Rows.AutoFit[/COLOR]
[COLOR=#333333]  Next[/COLOR]
[COLOR=#333333]End Sub[/COLOR]


Any ideas on what I might be doing wrong?

Thanks,
Sbrien
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.

Forum statistics

Threads
1,223,239
Messages
6,170,947
Members
452,368
Latest member
jayp2104

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