Hide next row based on drop down calue (yes or no)

slk1987

New Member
Joined
Dec 29, 2022
Messages
8
Office Version
  1. 2021
Platform
  1. Windows
Hi there,

Hoping someone can help me with the following:

I have a yes or no dropdown in cell J13 and would like to hide row 14 if the value in j13 is no.

If the value in j13 is yes, I would like row 14 to unhide.

I would like to run the code each time the value in J13 is changed.

Any assistance would be greatly appreciated.
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Right click on tab'name, View Code, then paste below code into
VBA Code:
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address(0, 0) <> "J13" Then Exit Sub
With Rows(14)
    Select Case Target.Value
        Case "Yes"
            .Hidden = True
        Case "No"
            .Hidden = False
    End Select
End With
End Sub
This code will trigger any change in cell J13
 
Upvote 0
Right click on tab'name, View Code, then paste below code into
VBA Code:
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address(0, 0) <> "J13" Then Exit Sub
With Rows(14)
    Select Case Target.Value
        Case "Yes"
            .Hidden = True
        Case "No"
            .Hidden = False
    End Select
End With
End Sub
This code will trigger any change in cell J13
Great, thank you for posting. I seem to be running into an issue posting it with the already existing VBA:

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim i&
If Intersect(Target, Range("C6:C7")) Is Nothing Then Exit Sub ' if C4 or C5 does not change then do nothing
With Sheets("Income Map") ' reference to A2:A72 of Income Map
.Rows("7:72").Hidden = False ' first, unhide all rows
For i = 7 To 72
If .Cells(i, 1).Value = 0 Then .Rows(i).Hidden = True ' hide rows those = 0
Next
End With
End Sub


How would I include both sections of code?

Thanks again!
 
Upvote 0
How would I include both sections of code?
  1. If these two are to be treated separately - which you should do for testing the new code - then paste it below any End Sub.
  2. If you are replacing your old code with the new code, then just Comment Block the entire old code block while you test the new code block.
  3. If you are trying to combine the two - I would have shared that code up front so people could advise based on that. Looks like you may need to wait for bebo to get back to you.
When sharing or posting code, it's recommended you use the Quick-wrap selection as VBA code on the toolbar.
1675182043431.png


... like so:

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim i&
If Intersect(Target, Range("C6:C7")) Is Nothing Then Exit Sub ' if C4 or C5 does not change then do nothing
With Sheets("Income Map") ' reference to A2:A72 of Income Map
.Rows("7:72").Hidden = False ' first, unhide all rows
For i = 7 To 72
If .Cells(i, 1).Value = 0 Then .Rows(i).Hidden = True ' hide rows those = 0
Next
End With
End Sub

I left out your Option Explicit because that's not part of the code block... but important to share that fact when asking for assistance.

When sharing directly for your Workbook, use this add-in if you are not already aware of it...
Best regards,
 
Last edited:
Upvote 0
Thank you for the feedback @zero269, here is what I have:

VBA Code:
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim i&
If Intersect(Target, Range("C6:C7")) Is Nothing Then Exit Sub ' if C4 or C5 does not change then do nothing
With Sheets("Income Map") ' reference to A2:A72 of Income Map
    .Rows("7:72").Hidden = False ' first, unhide all rows
    For i = 7 To 72
        If .Cells(i, 1).Value = 0 Then .Rows(i).Hidden = True ' hide rows those = 0
    Next
End With
End Sub

Private Sub Hide_Row(ByVal Target As Range)
If Target.Address(0, 0) <> "J13" Then Exit Sub
With Rows(14)
    Select Case Target.Value
        Case "No"
            .Hidden = True
        Case "Yes"
            .Hidden = False
    End Select
End With
End Sub

The worksheet_change sub is working but looks like an issue with the row hiding based on the value in J13. At this point, there is no change regardless of the value in J13.

Thanks!
 
Upvote 0
Hi there, just wanted to follow up here and see if anyone has thoughts on the discussion above. Appreciate any help.
 
Upvote 0

Forum statistics

Threads
1,224,813
Messages
6,181,117
Members
453,021
Latest member
Justyna P

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