Forum Discussion
Autofit Row Height when sorting
You can manually adjust the column width or row height or automatically resize columns and rows to fit the data.
Change the column width or row height in Excel
Additional Information:
Change the column width and row height
Hope I was able to help you with this info.
NikolinoDE
I know I don't know anything (Socrates)
- NikolinoDENov 20, 2021Gold Contributor
Here automatic adjustment with VBA on all cells
See the attached file with examples where you can try it out yourself.Enjoy excel
- deniserTHFeb 06, 2022Copper Contributor
Hello Niko...
Your example file below is exactly what I'm trying to do. But apparently I'm not be doing the VBA correctly, because it's not working for me either. I even tried copying your code exactly, but it didn't do a thing. (I've attached your example to clarify what I'm referring to.)
Zeilen_Spalten_auto_VBA.xlsmPreview file20 KBI resorted to creating a Macro/Button, but I'd rather it be done just as you have in your example, "Autofit Automatically". I was even able to use your example and I added Data/Filter/Sort, and even after sorting, it still works!If there are some specific steps to this VBA Code, I'd be most interested.- NikolinoDEFeb 06, 2022Gold Contributor
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)