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

ipbr21054

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

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
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,224,814
Messages
6,181,124
Members
453,021
Latest member
Justyna P

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