Macro to Hide Rows based on Cell Value - Not Working

sguidry

New Member
Joined
Mar 7, 2011
Messages
4
Hello,

I've written a macro that is supposed to hide/unhide rows based on a cell's value. I want it to run the macro whenever a certain cell is clicked, so the macro re-runs if the value of the specified cell is changed.

When I go to the cell and change the value, nothing happens. The case matches ('Yes', not 'yes'), and the values defined are correct - I am pulling my hair out trying to figure out what's wrong! :confused: Any help would be great.

Thank you!

Code:
Private Sub Worksheet_ShowYN(ByVal Target As Range)
Application.ScreenUpdating = True
 
'Participate in Program
If Target.Address = ("$B$17") Then
 
If Target.Value = "" Then
Rows("18:19").EntireRow.Hidden = True
End If
 
If Target.Value = "Yes" Then
Rows(18).EntireRow.Hidden = False
Rows(19).EntireRow.Hidden = True
End If
 
If Target.Value = "No" Then
Rows(19).EntireRow.Hidden = False
Rows(18).EntireRow.Hidden = True
End If
End If
End Sub
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Post the following into your worksheet event area.

Code:
 Private Sub Worksheet_Change(ByVal Target As Range)
For Each Cell In Range("B17")
        Select Case Cell.Value
            Case vbNullString
                Rows("18:19").EntireRow.Hidden = True
 
Case "Yes", "yes"
Rows(18).EntireRow.Hidden = False
Rows(19).EntireRow.Hidden = True
 
Case "No", "no"
Rows(19).EntireRow.Hidden = False
Rows(18).EntireRow.Hidden = True
  End Select
   Next
    End Sub
 
Upvote 0
Ah, that was it! I had changed the macro name, and I needed to keep it as

Private Sub Worksheet_Change

Thank you!
 
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,633
Latest member
DougMo

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