AutoFit Row and add 5 to row height via VBA

slivesay

Board Regular
Joined
Jan 4, 2019
Messages
64
I have a spreadsheet w/ vba coding to format the sheet via command button. It will autofit the row height, but when printing it cuts off the of some of the cells that contain a lot of wording. Is there a way to have it autofit and also add 5 more to the height via vba?
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
This will auto fit row 7 then add 5 to the height. change to fit what you need.

Code:
Sub adjrowheight()
Rows(7).AutoFit
myheight = Rows(7).RowHeight
Rows(7).RowHeight = myheight + 5

End Sub
 
Upvote 0
If you are trying to do more than 1 row, you could use something like
Code:
Sub slivesay()
   Dim i As Long
   
   Range("A1").CurrentRegion.EntireRow.AutoFit
   For i = 1 To Range("A" & Rows.Count).End(xlUp).Row
      Rows(i).RowHeight = Rows(i).RowHeight + 5
   Next i
End Sub
 
Upvote 0
Thank you both for the time and assistance. I used the coding Fluff gave and it is PERFECT! Fluff: THANK YOU AGAIN!
 
Upvote 0
Hello Fluff! :biggrin:

I have a question re: where this code should be located to max the codes ability to run correctly. I have the coding placed near the end (after the other formatting code). I'm finding that it will not auto size some of the rows to the correct size. It's either not enough & cutting off words or it is too much and the row is way bigger than needed. That being said w/in my code for the 'command button' used to format my sheet, should this particular coding be placed before or after other coding? All my coding is format based - like cell font size, alignment, adding borders, deleting certain columns, deleting blank rows, find/replace text, wrap/shrink to fit certain columns, column widths, totaling columns, sorting, password protect. (You've helped me with a few of the coding in other threads)

Thank you, again, for all the time and assistance you've provided me. I truly appreciate it! :biggrin:

Respectfully,
slivesay
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top