Hide Rows

N

newguy

I am trying to get this code to work where if a user enters an X in a
range of cells a corresponding group of rows is hidden further down in
the worksheet and I don't know what I am doing wrong.

Private Sub Worksheet_Change(ByVal Target As Range)
If Range("B5") = "X" Then
Range("B9:B15").EntireRow.Hidden = True
Else
Range("B9:B15").EntireRow.Hidden = False
End If

End Sub
 
S

Shasur

Hi

Your code doesn't hide any extra rows. Just in case if you want to reset it
before hidning you can try the following

Private Sub Worksheet_Change(ByVal Target As Range)
If Range("B5") = "X" Then
Rows.EntireRow.Hidden = False
Range("B9:B15").EntireRow.Hidden = True
Else
Rows.EntireRow.Hidden = False
Range("B9:B15").EntireRow.Hidden = False
End If

End Sub


Cheers
 
W

WhytheQ

Try this

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$B$5" Then
If Target = "X" Then
Range("B9:B15").EntireRow.Hidden = True
Else
Range("B9:B15").EntireRow.Hidden = False
End If
End If
End Sub
 
J

Joel

The code works fine so there are only threee reasons it is not working for your

1) You are typing a small x instead of a Capital x
2) The Macro is on the wrong worksheet. the code has to be on the VBA sheet
that coorresponds to the worksheet you are working with. The macro can't be
in a module sheet or THISWORKBOOK.
3) Macros or event are disabled Try running the code to enable events

Sub test()

Application.EnableEvents = True

End Sub


Also make sure none event macros are working. You workbook may bed in the
wrong security mode or if you have Medium security level then you may of
forgotten to enable macros when you opened the workbook.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top