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

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,602
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

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
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,221,418
Messages
6,159,791
Members
451,589
Latest member
Harold14

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