AutoFit an Entire Row Based on Text in a Specific Column Within the Row

bonzo

Board Regular
Joined
Oct 23, 2002
Messages
79
I need some VBA code for a situation where I have a row of 15 text cells and I want the auto-resize the entire row based the AutoFit of a particular column cell within the row. To explain in more detail, let's say that out of the 15 columns of text cells in a given row, column cells A-E, G-M, and O all have text such that the cell height is the standard 12.75, column cell N has a cell height of 50.00, and column cell F has a cell height of 25.00. With a normal AutoFit on the entire row, the row height would end up being 50.00. However, for presentation purposes, I want the row height for the entire row to be the row height of column cell F -- which would be 25.00 and would mean that only 25.00 worth of the text in column cell N would be visible. Is there an easy way to specify the entire row height to be AutoFit'ed based on a particular column cell within the row or do I have to write VBA code to manually check the required column cell height of column F and then manually set the row height for the entire row? Any help would be greatly appreciated!
 
I'm thinking font and font size are missing from your calculations and that's why the height calculations are too high.

maabadi, any suggestions on how to factor in the font (Arial) and font size (8pt) into the final height calculation?
 
Upvote 0

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
12pt font is like 1/6", i.e., there are 72 points in an inch. using your font size, you should be able to come up with an algorithm that reasonably approximates the necessary row height.
Use something like this to print a list of font sizes & row heights, and use the results to come up with your conversion formula.

VBA Code:
Sub Test()
Dim r As Range
Dim i as Integer

Set r = [a1]
r.EntireRow.AutoFit = True
For i = 1 to 10
    MsgBox "Row height = " & r.Height & vbCrLF & _
            "Font size = " & r.Font.Size
    Debug.Print r.Height & vbTab & r.Font.Size
    r.Font.Size = r.Font.Size + 1
Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,376
Messages
6,119,179
Members
448,871
Latest member
hengshankouniuniu

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