View Single Post
 
Old 09-15-2025, 05:19 PM
chrisjj chrisjj is offline Windows 7 64bit Office 97-2003
Competent Performer
 
Join Date: Aug 2025
Posts: 120
chrisjj is on a distinguished road
Default Excel 2003 - autofitting rows based only on selected column

I want one operation to set the height of all rows to the minimum height needed by any cell in Column O.

Any ideas?

I've tried everything from:

Code:
Worksheets("Sheet1").Columns("O").Rows.AutoFit
to ChatGPT's:

Code:
Sub AutofitRowsToColumnO()
    Dim ws As Worksheet
    Dim rng As Range
    Dim cell As Range
    Dim minHeight As Double
    
    Set ws = ActiveSheet
    ' Work on used range in Column O
    Set rng = ws.Range("O1:O" & ws.Cells(ws.Rows.Count, "O").End(xlUp).Row)
    
    Application.ScreenUpdating = False
    
    For Each cell In rng
        ' Autofit just this cell
        cell.EntireRow.AutoFit
        
        ' Now capture its required height
        minHeight = cell.RowHeight
        
        ' Reset row height to this minimum
        cell.EntireRow.RowHeight = minHeight
    Next cell
    
    Application.ScreenUpdating = True
End Sub

The best I ever get (even with all cells unmerged) seems to count in other columns, pranging the result. A workaround is to set all other columns to no Wrap Text and set my Col O to Yes Wrap Text.
Reply With Quote