VBA Code for 'do nothing'

ashleywanless

Board Regular
Joined
Aug 4, 2009
Messages
158
Hi

I need to know how to write in VBA to do nothing, not exit sub just move on to the next bit of code.

I have created a userform with lots of checkboxes, i want the code to check each box but if it is not checked then move onto the next checkbox. Code below

Private Sub ExportCommand_Click()
If EDCB.Value = False Then ???????
Else
MsgBox "You checked the box"
End If
End Sub

Also my form contains 15 checkboxes but some of these are either/or checkboxes i.e i need to return an error if both are selected. I know this peice of code needs to run first but any ideas on how to structure this?

Im guessing something like the above but if checkbox1.value = true and (how can i write and)
checkbox2.value = true then
message box error

Please let me know if this is unclear
End Sub
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
The easy fix is to change your logic:

Rich (BB code):
Private Sub ExportCommand_Click()
If EDCB.Value = True Then
MsgBox "You checked the box"
End If
End Sub

For your second question about checking multiple conditions, you do just what you asked to do ... use AND:

Rich (BB code):
If CheckBox1.Value = True AND Checkbox2.Value = True Then
MsgBox "Your Error Message Here"
End If
 
Upvote 0
You can shorten your first code to:

Code:
Private Sub ExportCommand_Click()
    If EDCB.Value = True Then MsgBox "You checked the box"
End Sub
 
Upvote 0
You should add code for the paired checkboxes so that if one is checked, the other is unchecked e.g.
Code:
Private Sub CheckBox1_Click()
    If CheckBox1.Value Then CheckBox2.Value = False
End Sub

Private Sub CheckBox2_Click()
    If CheckBox2.Value Then CheckBox1.Value = False
End Sub

Both cant be selected. Then you wouldn't have to check if they are configured (error) properly.
 
Upvote 0

Forum statistics

Threads
1,221,596
Messages
6,160,716
Members
451,665
Latest member
PierreF

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