Code to hide a row or make 0 height based on drop down cell

jrisebo

Active Member
Joined
Mar 15, 2011
Messages
311
Office Version
  1. 365
Platform
  1. Windows
Anyway to hide a row based on a cell value? I have a cell with "Yes" "no" value, if "No", I want it to hide the row below
Thanks
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
You can use VBA to do that.
You can either have code that you run manually to do it, or you can have VBA code that runs automatically when some cell is manually updated.

If you are interested in either solution, please provide more details (i.e. exactly where you will be entering these "Yes" and "No" values).
 
Upvote 0
You can use VBA to do that.
You can either have code that you run manually to do it, or you can have VBA code that runs automatically when some cell is manually updated.

If you are interested in either solution, please provide more details (i.e. exactly where you will be entering these "Yes" and "No" values).
Thanks. So Cell C17 will be a drop down, yes or no. I want row 18 to be hidden if answer is no.
Thanks
 
Upvote 0
This for cell C17:
Place in worksheet module (Right click on sheet name/ View code than paste below code into)
VBA Code:
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Application.ScreenUpdating = False
If Intersect(Target, Range("C17")) Is Nothing Then Exit Sub
With Target.Offset(1, 0).EntireRow
    .Hidden = False
    If Target.Value = "Yes" Then
        .Hidden = False
    Else
        .Hidden = True
    End If
End With
Range("C17").Select
Application.ScreenUpdating = True
End Sub
 
Upvote 0
This for cell C17:
Place in worksheet module (Right click on sheet name/ View code than paste below code into)
VBA Code:
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Application.ScreenUpdating = False
If Intersect(Target, Range("C17")) Is Nothing Then Exit Sub
With Target.Offset(1, 0).EntireRow
    .Hidden = False
    If Target.Value = "Yes" Then
        .Hidden = False
    Else
        .Hidden = True
    End If
End With
Range("C17").Select
Application.ScreenUpdating = True
End Sub
When I choose "no" it hides row 18, but when switch back to yes, it does not unhide.
 
Upvote 0
Try these tweaks to bebo0219999's original code, which works for any case (i.e. "YES", "Yes", "yes"), and accounts for the possibility of multiple cells being updated at once.
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

    If Intersect(Target, Range("C17")) Is Nothing Then Exit Sub

    With Range("C17").Offset(1, 0).EntireRow
        .Hidden = False
        If LCase(Range("C17").Value) = "yes" Then
            .Hidden = False
        Else
            .Hidden = True
        End If
    End With

End Sub
 
Last edited:
Upvote 0
Solution
You are welcome.
Glad we could help!
 
Upvote 0

Forum statistics

Threads
1,214,651
Messages
6,120,744
Members
448,989
Latest member
mariah3

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