Hiding selected Row

R

Ruan

Hello,

I would like to hide an entire row, only if the User selects a "X" in Column
B.

Below is the code I used to hide rows that had blank values in Column B. How
would I modify this code to look for a "X" value?

Sub HideRows1()
Worksheets("Jul").Unprotect Password:="abcd"

' Hide Selected Rows on the Worksheet
With Range("B11:B119")
.EntireRow.Hidden = False
.SpecialCells(xlCellTypeBlanks).EntireRow.Hidden = True
End With
Range("C11").Select
Worksheets("Aug").Protect Password:="abcd", Scenarios:=True

End Sub


Thanks
Ruan
 
C

Chan

Try this:

Sub HideRows1()
Worksheets("Jul").Unprotect Password:="abcd"

' Hide Selected Rows on the Worksheet
For each c in ("B11:B119")
If c.value = "X" then
..EntireRow.Hidden = True
Else
..EntireRow.Hidden = False
End if
Next

Range("C11").Select
Worksheets("Aug").Protect Password:="abcd", Scenarios:=True

End Sub
 
T

Tom Ogilvy

If the cells will either be blank or contain an X then

Sub HideRows1()
Worksheets("Jul").Unprotect Password:="abcd"

' Hide Selected Rows on the Worksheet
With Range("B11:B119")
.EntireRow.Hidden = False
On Error Resume Next
.SpecialCells(xlConstants,xlTextValues).EntireRow.Hidden = True
On Error goto 0
End With
Range("C11").Select
Worksheets("Aug").Protect Password:="abcd", Scenarios:=True

End Sub
 
R

Ruan

Thanks Chan. I get an error when I run the code though. I will keep playing
with it.
Ruan
 
R

Ruan

Thanks Tom. It works great.


Tom Ogilvy said:
If the cells will either be blank or contain an X then

Sub HideRows1()
Worksheets("Jul").Unprotect Password:="abcd"

' Hide Selected Rows on the Worksheet
With Range("B11:B119")
.EntireRow.Hidden = False
On Error Resume Next
.SpecialCells(xlConstants,xlTextValues).EntireRow.Hidden = True
On Error goto 0
End With
Range("C11").Select
Worksheets("Aug").Protect Password:="abcd", Scenarios:=True

End Sub
 

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