![]() |
|
|
|
#1
|
|||
|
|||
|
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
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. |
|
#2
|
||||
|
||||
|
try:
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
minHeight = 1E+99
For Each cell In rng
cell.Rows.AutoFit
minHeight = Application.Min(minHeight, cell.RowHeight)
Next cell
rng.EntireRow.RowHeight = minHeight
Application.ScreenUpdating = True
End Sub
|
|
#3
|
|||
|
|||
|
Thank you.
|
|
| Tags |
| excel 2003 |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Dynamic Header and footer in word document based upon company selected in excel. | starmumbai | Mail Merge | 4 | 02-02-2022 10:12 PM |
Delete blank table rows in merged document and split document in docx and pdf based on excel rows
|
Alex1s85 | Word VBA | 5 | 05-22-2021 12:05 PM |
Set Range based on selected rows.
|
14spar15 | Excel Programming | 8 | 11-19-2018 08:08 AM |
Insert values from multiple rows based on value in one column
|
pachmarhi | Excel | 3 | 07-18-2014 09:57 PM |
Referencing rows of a table at a bookmarked location based on the value of a column
|
jpb103 | Word VBA | 11 | 05-22-2014 08:33 AM |