Conditional Hide Rows Macro

C

cchubba

I want a macro to do a conditional hide automatically based on another
value in another cell.

For example:

If Cell A1 = "Yes" then hide rows 20:23
If Cell A1 = "No" then do not hide rows 20:23


The closest thing i can find is the below example which hides the row
based on the value (in the same row) in column T




Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Select Case Range("T" & Target.Row).Value
Case Is = "Y"
Target.EntireRow.Hidden = True
Case Is = "N"
Target.EntireRow.Hidden = False
End Select
End Sub
 
C

colofnature

Try this:

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Select Case ucase(Range("a1").Value)
case "YES"
[20:23].entirerow.hidden = true
case else
[20:23].entirerow.hidden = false
End Select
End Sub


Col
 
D

Don Guillett

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address <> "$A$1" Then Exit Sub

If UCase(Target) = "Y" Then
Rows("20:23").Hidden = True
Else
Rows("20:23").Hidden = False
End If
End Sub

another idea just assigned to a button
sub hideunhidecolg()
Columns("g").EntireColumn.Hidden = Not Columns("g").EntireColumn.Hidden
end sub
 
C

cchubba

colofnature said:
Try this:

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Select Case ucase(Range("a1").Value)
case "YES"
[20:23].entirerow.hidden = true
case else
[20:23].entirerow.hidden = false
End Select
End Sub


Col

That works great! Thanks
 

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