VBA to auto adjust row height to fit Text

Socrates055

New Member
Joined
Sep 12, 2017
Messages
4
I am using Excel 2010 and my data is variable in number of rows and length of text in each cell and Wrap Text is on. What would be the VBA code to automatically adjust row height from $A$3:INDIRECT("$R$&"COUNT(D:D)) to fit text but have a minimum row height of 27.
~INDIRECT() Gives me the last cell in my data~

Since my text is Arial Size 6 (I need to keep zoom at 115%) using the built in Autofit Row Height causes the height to be 8.25 if its a single line of text.

To sum up, I would like a way to have Excel auto adjust row height to fit text string but have a minimum row height set at 27.
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Something like this?
Code:
Sub RowHeightMin()
    Dim finalRow As Integer
    Dim i As Integer
    
    finalRow = Cells(Rows.Count, 1).End(xlUp).Row
    
    Range("A1:A" & finalRow).EntireRow.AutoFit
    
    For i = 2 To finalRow
        If Range("A" & i).EntireRow.RowHeight < 27 Then
            Range("A" & i).EntireRow.RowHeight = 27
        End If
    Next i
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,746
Messages
6,126,642
Members
449,325
Latest member
Hardey6ix

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