How to stop excel revealing the hidden rows when double clicking on a range of row headers?

arxoon

New Member
Joined
Apr 2, 2023
Messages
4
Office Version
  1. 2021
I have some rows that I have hidden. I need to adjust the row height of some rows. When I select the row headers including the hidden rows and double click to automatically adjust the row height, the hidden rows get unhid. How to stop this beheaviour of excel?
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Select the rows then go to Home>Editing>Find&Select>GoTo...>Special>Visible Cells Only>OK. Then double click to resize the rows.
If you need to do regularly, you can add a Select Visible Cells button to the QAT.
 
Last edited:
Upvote 0
Is it a normal behaviour? I don't remember hidden rows getting unhid when double clicking to adjust row heights.
 
Upvote 0
Is it a normal behaviour? I don't remember hidden rows getting unhid when double clicking to adjust row heights.
Yes, I think it's normal - if you select the hidden rows.
 
Upvote 0
Is there any way to stop excel from unhiding such hidden rows on double clicking?
 
Upvote 0
Here's a macro :
VBA Code:
Sub V()
Selection.SpecialCells(xlCellTypeVisible).Rows.AutoFit
End Sub
I suggest that you put a button on the QAT.
Then select the rows (including the hidden rows) and click the button.
 
Upvote 0
Could you please tell me how to put the button in quick access toolbar?
 
Upvote 0
To make sure the hidden rows remain hidden automatically without the need for buttons etc, you can use the following trick :

1- Select the rows that you want to be hidden and give them a Range Name (such as HiddenRows). You can do this via the Names dropdown located to the left of the formula bar. (circled in red in the image below) and then press the Enter key.

In this example, we will assume the hidden rows are 11:13
HiddenRows.png


2-
Once the named range is defined for the hidden rows as described above, add a formula with a volatile function to a cell in the worksheet. Easiest one is probably the formula =Now() ... I would place this formula in some cell at the far bottom of the worksheet so it can't be seen.

3- Hide the Rows.

4- Place this code in the Worksheet Module:
VBA Code:
Option Explicit

Private Sub Worksheet_Calculate()
    If IsRangeVisible(Range("HiddenRows")) Then
        Range("HiddenRows").EntireRow.Hidden = True
    End If
End Sub

Private Function IsRangeVisible(ByVal oRange As Range) As Boolean
    Dim lRowsCount As Long
    On Error Resume Next
    lRowsCount = oRange.EntireRow.SpecialCells(xlCellTypeVisible).Count
    IsRangeVisible = CBool(lRowsCount)
End Function

From now on, the rows should remain hidden no matter what.

To unhide the rows, you could temporarly comment out the code inside the Worksheet_Calculate event.
 
Upvote 0

Forum statistics

Threads
1,215,330
Messages
6,124,310
Members
449,152
Latest member
PressEscape

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top