VBA - Hide rows based on Cell value.

OversizedCranium

New Member
Joined
Aug 18, 2015
Messages
26
Office Version
  1. 365
Platform
  1. Windows
Hi all,

Appreciate this is pretty basic, but I'm struggling to use google to make it work,

For context I'm making a tab which is in a form style format, people fill out and all the calculations are done in the background, however I want to make it as less noisy as possible...

So when Cell C18 in this instance = "No", I want to hide rows 19-39, but when it is populated back to yes, I want the rows to come back, can anyone help me out? I Appreciate there are very similar questions to this one, but due to my absolute zero knowledge of VBA I'm struggling to translate to my own circumstance.

Thanks All,

Callum
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Try this:
This is an auto sheet event script
Your Workbook must be Macro enabled
To install this code:
Right-click on the sheet tab
Select View Code from the pop-up context menu
Paste the code in the VBA edit window

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
'Modified  11/12/2020  5:50:05 AM  EST
If Target.Cells.CountLarge > 1 Or IsEmpty(Target) Then Exit Sub
If Target.Address = Range("C18").Address Then
    If Target.Value = "No" Then Rows(19).Resize(21).Hidden = True
    If Target.Value = "Yes" Then Rows(19).Resize(21).Hidden = False
End If
End Sub
 
Upvote 0
Maybe
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Target, Range("C18")) Is Nothing Then
        If Range("C18").Value = "NO" Then
            Rows("19:39").EntireRow.Hidden = True
        Else
            Rows("19:39").EntireRow.Hidden = False
        End If
    End If
End Sub
 
Upvote 0
Try this:
This is an auto sheet event script
Your Workbook must be Macro enabled
To install this code:
Right-click on the sheet tab
Select View Code from the pop-up context menu
Paste the code in the VBA edit window

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
'Modified  11/12/2020  5:50:05 AM  EST
If Target.Cells.CountLarge > 1 Or IsEmpty(Target) Then Exit Sub
If Target.Address = Range("C18").Address Then
    If Target.Value = "No" Then Rows(19).Resize(21).Hidden = True
    If Target.Value = "Yes" Then Rows(19).Resize(21).Hidden = False
End If
End Sub
Life saver!

Thanks a lot
 
Upvote 0
Try this:
This is an auto sheet event script
Your Workbook must be Macro enabled
To install this code:
Right-click on the sheet tab
Select View Code from the pop-up context menu
Paste the code in the VBA edit window

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
'Modified  11/12/2020  5:50:05 AM  EST
If Target.Cells.CountLarge > 1 Or IsEmpty(Target) Then Exit Sub
If Target.Address = Range("C18").Address Then
    If Target.Value = "No" Then Rows(19).Resize(21).Hidden = True
    If Target.Value = "Yes" Then Rows(19).Resize(21).Hidden = False
End If
End Sub
Sorry to bother you further,

What's the logic in the 21? so if I wanted to apply this to different rows and adifferent cell, what am I ammending?

Cheers,
 
Upvote 0
Sorry to bother you further,

What's the logic in the 21? so if I wanted to apply this to different rows and adifferent cell, what am I ammending?

Cheers,
Give me a couple examples of other other rows. And I will show you.
And will it always be Yes No
 
Upvote 0
Try this:
Add more if you want:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
'Modified  11/12/2020  7:00 AM  EST
If Target.Cells.CountLarge > 1 Or IsEmpty(Target) Then Exit Sub

Select Case Target.Address

        Case "$C$18"
            If Target.Value = "No" Then Rows("19:39").Hidden = True
            If Target.Value = "Yes" Then Rows("19:39").Hidden = False
    
        Case "$C$46"
            If Target.Value = "No" Then Rows("47:49").Hidden = True
            If Target.Value = "Yes" Then Rows("47:49").Hidden = False

End Select

End Sub
 
Upvote 0

Forum statistics

Threads
1,214,584
Messages
6,120,387
Members
448,956
Latest member
JPav

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