Code continues to run when it should have stopped & exit sub

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,731
Office Version
  1. 2007
Platform
  1. Windows
Part of my code is to check whether either of my two checkboxes have a selection.

I have CheckBox1 & Checkbox2

This is what i have in place BUT when neither of the checkboxes have been selected the following code should stop BUT it continues to run.

VBA Code:
    If CheckBox1 & CheckBox2 = False Then
    MsgBox "NEITHER CHECKBOX WAS SELECTED", vbCritical, "NO CHECKBOX WAS SELECTED MESSAGE"
    Exit Sub
    End If
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Update
This worked if i wrote it for 1 checkbox so how is it correctly written to allow BOTH checkboxes in one line of code without having to write the code twice

VBA Code:
    If CheckBox1 = False Then
    MsgBox "NEITHER CHECKBOX WAS SELECTED", vbCritical, "NO CHECKBOX WAS SELECTED MESSAGE"
    Exit Sub
    End If
 
Upvote 0
Code:
If CheckBox1 = False and checkbox2 = false then

Should do it
 
Upvote 0
Solution
@RoryA can you advise on this also please.

 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,195
Members
452,616
Latest member
intern444

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