Need help making VBA OR statement

Ancient Wolf

Board Regular
Joined
Mar 17, 2009
Messages
89
Hello. Once again, I seem to be snagged.

I was wondering how to turn this VBA Code:

If Target.Address(False, False) = "B3" Then
ActiveSheet.Unprotect
Rows("25:32").Hidden = Target.Value <> "strawberries"
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
End If

So that it will look at strawberries or cherries and then hide and unhide the rows specified in the coding. Any ideas? I tried using an Else statement, but that ended in error. Placing the code like this:

If Target.Address(False, False) = "B3" Then
ActiveSheet.Unprotect
Rows("25:32").Hidden = Target.Value <> "strawberries"
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
End If
If Target.Address(False, False) = "B3" Then
ActiveSheet.Unprotect
Rows("25:32").Hidden = Target.Value <> "cherries"
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
End If

just causes the code to conflict with itself.

Thank you for the help.
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Perhaps

Rows("25:32").Hidden = Target.Value <> "strawberries" And Target.Value <>"cherries"
 
Upvote 0
Thank you, VoG. That appears to be working. I still have a lot to learn about the VBA codes, so I really appreciate the help that you guys and gals give me.
 
Upvote 0

Forum statistics

Threads
1,224,613
Messages
6,179,901
Members
452,948
Latest member
Dupuhini

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