Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 09-15-2025, 05:19 PM
chrisjj chrisjj is offline Excel 2003 - autofitting rows based only on selected column Windows 7 64bit Excel 2003 - autofitting rows based only on selected column Office 97-2003
Competent Performer
Excel 2003 - autofitting rows based only on selected column
 
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
 

Tags
excel 2003

Thread Tools
Display Modes


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
Excel 2003 - autofitting rows based only on selected column 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
Excel 2003 - autofitting rows based only on selected column Set Range based on selected rows. 14spar15 Excel Programming 8 11-19-2018 08:08 AM
Excel 2003 - autofitting rows based only on selected column Insert values from multiple rows based on value in one column pachmarhi Excel 3 07-18-2014 09:57 PM
Excel 2003 - autofitting rows based only on selected column 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

Other Forums: Access Forums

All times are GMT -7. The time now is 11:39 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft