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

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
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,217,440
Messages
6,136,640
Members
450,022
Latest member
Joel1122331

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