Noobee Case Select Question

C

CH

I have the following code below in which I want it to check the value
of two cells and if the two cells = certain values then hide rows on a
different sheet.

For example if A12 = "BLUE" AND B16 = "DOG" then hide rows on sheet
"CAR" Else dont hide the rows.

I prefer to use the case select statement but the code below doesn't
work. Why?


'Case Select
'=====================================
Select Case testcase
Case UCase(Range("A12").Value = "Blue", Range("D27") = "Dog")
Sheets("Car").Rows("1:20").EntireRow.Hidden = True
Case Else
Sheets("Car").Rows("1:20").EntireRow.Hidden = False
End Select

End Sub
 
C

CH

CH said:
I have the following code below in which I want it to check the value
of two cells and if the two cells = certain values then hide rows on a
different sheet.

For example if A12 = "BLUE" AND B16 = "DOG" then hide rows on sheet
"CAR" Else dont hide the rows.

I prefer to use the case select statement but the code below doesn't
work. Why?


'Case Select
'=====================================
Select Case testcase
Case UCase(Range("A12").Value = "Blue", Range("B16") = "Dog")
Sheets("Car").Rows("1:20").EntireRow.Hidden = True
Case Else
Sheets("Car").Rows("1:20").EntireRow.Hidden = False
End Select

End Sub
 
J

Jim Cone

Change the word "testcase" to True.
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware


"CH" <[email protected]>
wrote in message
I have the following code below in which I want it to check the value
of two cells and if the two cells = certain values then hide rows on a
different sheet.
For example if A12 = "BLUE" AND B16 = "DOG" then hide rows on sheet
"CAR" Else dont hide the rows.
I prefer to use the case select statement but the code below doesn't
work. Why?

'Case Select
'=====================================
Select Case testcase
Case UCase(Range("A12").Value = "Blue", Range("D27") = "Dog")
Sheets("Car").Rows("1:20").EntireRow.Hidden = True
Case Else
Sheets("Car").Rows("1:20").EntireRow.Hidden = False
End Select
End Sub
 
D

Dave Peterson

This looks more natural as If/then/Else that select case (to me, anyway):

if UCase(Range("A12").Value) = ucase("Blue") _
and ucase(Range("D27").value) = ucase("Dog") then
Sheets("Car").Rows("1:20").EntireRow.Hidden = True
Else
Sheets("Car").Rows("1:20").EntireRow.Hidden = False
End if

Remember that if you're using ucase(), you'll want to compare uppercase strings:

ucase(anything) will never equal "Dog". It may equal "DOG", though.
 
C

CH

Jim said:
Change the word "testcase" to True.
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware


"CH" <[email protected]>
wrote in message
I have the following code below in which I want it to check the value
of two cells and if the two cells = certain values then hide rows on a
different sheet.
For example if A12 = "BLUE" AND B16 = "DOG" then hide rows on sheet
"CAR" Else dont hide the rows.
I prefer to use the case select statement but the code below doesn't
work. Why?

'Case Select
'=====================================
Select Case testcase
Case UCase(Range("A12").Value = "Blue", Range("B16") = "Dog")
Sheets("Car").Rows("1:20").EntireRow.Hidden = True
Case Else
Sheets("Car").Rows("1:20").EntireRow.Hidden = False
End Select
End Sub

Thanks Jim, that worked (so it will now hide the rows) BUT for some
reason its only hiding/unhiding the rows based on the value of B16 =
"DOG". It seems like it's ignoring the value of A12. The rows will
hide only when B16 = "Dog" in stead of when A12 = "Blue" AND B16 =
"Dog".

P.S. also it didnt like my UCASE for some reason so i took it out


'Case Select
'=====================================
Select Case True
Case Range("A12").Value = "Blue", Range("B16").Value = "Dog"
Sheets("Car").Rows("1:20").EntireRow.Hidden = True
Case Else
Sheets("Car").Rows("1:20").EntireRow.Hidden = False
End Select
End Sub
 
C

CH

Dave said:
This looks more natural as If/then/Else that select case (to me, anyway):

if UCase(Range("A12").Value) = ucase("Blue") _
and ucase(Range("D27").value) = ucase("Dog") then
Sheets("Car").Rows("1:20").EntireRow.Hidden = True
Else
Sheets("Car").Rows("1:20").EntireRow.Hidden = False
End if

Remember that if you're using ucase(), you'll want to compare uppercase strings:

ucase(anything) will never equal "Dog". It may equal "DOG", though.


Thanks Dave. This seems to work.

ch
 
D

Don Guillett

Unless you have a lot of these, in this limited case (pun intended) I would
use a simple if instead

with sheets("car")
.rows.hidden=false
if ucase(range("a12")="DOG" and ucase(range("b16")="CAR" then _
.rows("1:20").hidden=true
end with
 

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