Autosize Row Height based on Visible cells only

nimesh29

New Member
Joined
Mar 20, 2013
Messages
26
I am trying to Autosize Row height based on Visible cells only and not the Hidden columns. I have columns that has very long text that I will be hiding and then I am left with extra white space in other cells and extra long worksheet.

I tried formatting the Autofit cells Row height but, it adjust it based on cells in hidden columns. I searched and found few codes but, nothing seems to do what I am trying to do.

Thanks for your help with this.

Nimesh
 

shknbk2

Board Regular
Joined
Mar 5, 2016
Messages
235
What if you format the cells of the hidden columns as NOT word wrapped? When hidden, the text that would extend beyond also gets hidden. I guess this won't work, however, if the cell value has newline characters (Alt+Enter).
 
Last edited:

JoeMo

MrExcel MVP
Joined
May 26, 2009
Messages
16,669
Select the rows you want to resize, then run this. If the first row of the selection doesn't have a row height you like, pick another row (red font) or just use a numerical row height on the right side of the equal sign.
Rich (BB code):
Sub test()
'change row number within selection to suit
Selection.RowHeight = Selection.Rows(1).RowHeight
End Sub
 

nimesh29

New Member
Joined
Mar 20, 2013
Messages
26
Thanks Joe this works for individual Rows. But, I am trying to change all affected rows in the sheet.
I found a code that will do that but, it doesn't play nice with Merged cells in one of the column when I hide the other column.

Code:
Code:
Sub AutoFitRow()

    Dim rngRow As Range
    Dim rngAutofit As Range
    Dim rngCopy As Range
    
    Set rngAutofit = Range("A501")
    For Each rngRow In Range("A2:A500").Rows
        rngRow.EntireRow.SpecialCells(xlCellTypeVisible).Copy rngAutofit
        rngAutofit.EntireRow.AutoFit
        rngRow.RowHeight = rngAutofit.RowHeight
    Next
    rngAutofit.EntireRow.Clear
    
End Sub
Link to File:
https://we.tl/t-Qrn77sNnJ9
 

Forum statistics

Threads
1,082,367
Messages
5,365,028
Members
400,819
Latest member
Gossow

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top