Forum Discussion
Autofit Row Height when sorting
VBA code "behind" a worksheet or a workbook may not work in Excel
o edit code "behind" a worksheet or a workbook:
Activate the Visual Basic Editor (press ALT+F11).
In the Project Explorer window, you will see entries similar to the following:
Copy this Code in the Worksheet you like
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Target.EntireRow.AutoFit
Target.EntireColumn.AutoFit
End Sub
With this you don't need a button or any other jump starter, the sheet should behave just like the sheet I sent you. If you cannot manage it on your PC, I can only help if you send me the file (without sensitive data).
*Knowing the Excel version, as well as the operating system and storage medium (OneDrive, hard drive, Sharepoint, etc.) would be an advantage to share more detailed information.
Thank you for your understanding and patience
I know I don't know anything (Socrates)
When looking at your formula above in black... I highlighted my entire sheet and typed just as yours above, which did not work. Should I replace some words with my excel worksheet/tab name?
- NikolinoDEDec 21, 2022Gold ContributorSo it works for me (Excel 2016). Did you save the file as .Xlsm?
- Kingram01Dec 21, 2022Copper Contributor
NikolinoDE I was able to get it to work on one of my workbooks and actually was able to remove column autofit and it still worked after sorting multiple different ways. Now my issue is.... I cant get it to do the same thing on another workbook by following the same exact example. It is odd. I have saved my add in and tried that as well with no luck. What am I doing wrong?
- NikolinoDEDec 21, 2022Gold ContributorRight off the bat I can't suggest a solution to you, I could only give you guesses that might be very time-consuming. Please paste the file with the problem (and without sensitive data), that would help both of us to see where the error in this file could be.
- Kingram01Dec 21, 2022Copper ContributorI figured it out and it worked like a wonder! This is awesome!!!