Multiple Condition with If...Thens in VBA

NeilK

New Member
Joined
May 15, 2003
Messages
9
Hi All,

I can't for the life of me figure out how to do this...basically I am trying to use an IF...THEN formula with ANDs and ORs such as If "A" And "B" Then "Do This" And "Do That".

More specificially, I have two sheets (i.e. "Red" and "Blue")in my workbook and a combo box on each sheet that would call different UserForms. What I am trying to write is...
----------------
Private Sub Workbook_SheetActivate(ByVal Sheet As Object)

If ActiveSheet.Name = "Red" And ComboBox1.Value = "Report 1" Then
Unload UserForm1 And UserForm2.Show
Else Unload UserForm2 and UserForm1.Show

If ActiveSheet.Name = "Blue" And ComboBox2.Value = "Report 1" Then
Unload UserForm4 And UserForm3.Show
Else Unload UserForm3 and UserForm4.Show

----------------

Any help with this would be greatly appreciated! I've tried the SELECT CASE method too but can't get that to work either...HELP!!!!

Thanks,

Neil
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
NeilK said:
Hi All,

I can't for the life of me figure out how to do this...basically I am trying to use an IF...THEN formula with ANDs and ORs such as If "A" And "B" Then "Do This" And "Do That".

More specificially, I have two sheets (i.e. "Red" and "Blue")in my workbook and a combo box on each sheet that would call different UserForms. What I am trying to write is...
----------------
Private Sub Workbook_SheetActivate(ByVal Sheet As Object)

If ActiveSheet.Name = "Red" And ComboBox1.Value = "Report 1" Then
Unload UserForm1 And UserForm2.Show
Else Unload UserForm2 and UserForm1.Show

If ActiveSheet.Name = "Blue" And ComboBox2.Value = "Report 1" Then
Unload UserForm4 And UserForm3.Show
Else Unload UserForm3 and UserForm4.Show

----------------

Any help with this would be greatly appreciated! I've tried the SELECT CASE method too but can't get that to work either...HELP!!!!

Thanks,

Neil

Pretty Close

If ActiveSheet.Name = "Red" And ComboBox1.Value = "Report 1" Then
Unload UserForm1
UserForm2.Show
Else
Unload UserForm2
UserForm1.Show
End if

If ActiveSheet.Name = "Blue" And ComboBox2.Value = "Report 1" Then
Unload UserForm4
UserForm3.Show
Else
Unload UserForm3
UserForm4.Show
End if

This should work.
 
Upvote 0

Forum statistics

Threads
1,202,923
Messages
6,052,581
Members
444,593
Latest member
Smaxls

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