Easy Autofit with VBA 🚧

Gone are the days when we need to manually fidget with column widths as we enter our data, and thank goodness.  Let's learn how to leverage a simple VBA code (don't panic!) to automatically resize our columns to fit what we're typing!

Check out the gif above for an example - first, we need to open our worksheet's VBA code by right-clicking the sheet, selecting "view code", and selecting "worksheets" in the dropdown.  Now we'll just enter the code 'cells.entirecolumn.autofit' after the first existing line of code, and that's it!  Close out of the VBA code, type the longest column header your heart desires, and watch as the cell now magically updates to fit the size of your data!

 

I wish this was an automatic setting in Excel - what do you guys think?!?  Have fun trying this out!

Back to blog

Meet Emma

Emma is the founder of Excel Dictionary, your ultimate source for impactful, digestible Excel tips and tricks.  After graduating from The Ohio State University in 2019 with a degree in Actuarial Science, Emma began her professional career as an actuary, just in time for COVID to hit.  New to the industry, new to the company, adjusting to a new WFH environment, and new to Excel, Emma quickly realized how overwhelming those Excel projects could be and didn’t know where to turn for help – so she taught herself.

Emma created Excel Dictionary to help others avoid Excel overwhelm and to be the coworker that you can turn to.  She was recently awarded the Microsoft MVP award and has built a community of over 7 million people across the globe! Join her across all social channels to learn quick, actionable skills that will make you more efficient, comfortable, and confident in your daily work!

Follow Emma