This is the default ThisWorkbook code:
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
FixWidthHeight
End Sub
And this is my FixWidthHeight module:
Sub FixWidthHeight()
Cells.Select
Selection.Columns.AutoFit
Selection.Rows.AutoFit
Application.Goto ActiveCell.EntireRow, True
End Sub
What I want my code to do and in this particular order:
- Cells.Select - Selects all cells in the entire worksheet
- Selection.Columns.AutoFit - Autofits all column width
- Selection.Rows.AutoFit - Autofits all row height
- Application.Goto ActiveCell.EntireRow, True - Scrolls the last updated row to the top of the worksheet
The problem I have with this code is that it will not fire the last property Application.Goto ActiveCell.EntireRow, True because the Cells.Select property prevents it from firing. I have tested the code and found Cells.Select to be the culprit. When Cells.Select property is fired, it automatically jumps to the first row on the top of the worksheet and not the last active/updated row. It's as if Cells.Select cancels out Application.Goto ActiveCell.EntireRow, True and that is not what I want. So I would like to know if someone can help me fix this code to obtain my desired results specified. Thank you