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.