Expand / Collapse Rows based a Cell Value

User2000

New Member
Joined
Oct 10, 2016
Messages
8
Hi,

I have a cell A1 that will either be "Yes" or "No".

I have cells(rows) A2-A11 that are grouped and defaulted as collapsed/hidden. I want these rows to automatically expand if A1 is "Yes". Is this possible?
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Hi, you need to insert this in the sheet in question (not a module)

Code:
Private Sub Worksheet_Change(ByVal Target As Range)


    Dim KeyCells As Range

    Set KeyCells = Range("A1")
    
    If Not Application.Intersect(KeyCells, Range(Target.Address)) _
        Is Nothing Then

        If Range("A1") = "Yes" Then
            Rows("2:11").Select
            Selection.EntireRow.Hidden = False
            Range("A1").Select
       End If
   
    End If
    
End Sub
 
Last edited:
Upvote 0
Thanks! That did the job, however I got an error with this line and Excel crashes every time when I try to debug:

Selection.EntireRow.Hidden = False

I am not competent enough with VBA to understand why. Any further comments would be greatly appreciated!
 
Upvote 0
Hmm, maybe a version issue?

Try this:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)



    Dim KeyCells As Range


    Set KeyCells = Range("A1")
    
    If Not Application.Intersect(KeyCells, Range(Target.Address)) _
        Is Nothing Then


        If Range("A1") = "Yes" Then
            Rows("2:11").Select
            On Error Resume Next
            Selection.EntireRow.Hidden = False
            Range("A1").Select
       End If
   
    End If
     
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,914
Messages
6,175,351
Members
452,638
Latest member
Oluwabukunmi

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