PDA

View Full Version : Refresh autofit row using VBA excel



radujit
03-26-2015, 12:33 PM
Hi,
I have some text in Sheet 1 that is dynamically changing depending on input (multiple variables) from another sheet (Sheet 2).
I need some VBA that would refresh the autofit row property in Sheet1 when variables change in Sheet2.
Any help would be greatly appreciated.

Bob Phillips
03-27-2015, 10:06 AM
Off the top

Add this code to the sheet2 worksheet module and change $A$21 and Rows(10) to suit.


Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Address = "$A$1" Then

Worksheets("Sheet1").Rows(10).AutoFit
End If
End Sub

Zack Barresse
03-27-2015, 11:13 AM
Would this value on sheet 2 change while you were on sheet 1? If not I'd recommend the worksheet activate method instead of the change method. This is because you'll lose your undo stack for every change as opposed to once when activating the sheet.