Running Check box code after Command button Click

T

Todd

Private Sub CommandButton1_Click()
Call CheckBox2_Click
End Sub

I have code like the following and it works almost like I
want it to, but when I check the checkbox it will activate
the Form worksheet I have. I do not want anything to
happen until after the command button is pressed. What
can I add or remove to this code to allow this to happen?
Thanks!

Option Explicit

Private Sub CommandButton1_Click()
Call CheckBox2_Click
End Sub

Private Sub CheckBox2_Click()
Sheets("Form").Activate
ActiveSheet.Range("Address").Select
If Selection.Interior.Pattern = xlNone Then
With Selection.Interior
.ColorIndex = 6
.Pattern = xlSolid
End With
Else
With Selection.Interior
.Pattern = xlNone
End With
End If
End Sub
 
D

Dave Peterson

Maybe just work on the range directly:

Private Sub CheckBox2_Click()
With workSheets("Form").Range("Address")
If .Interior.Pattern = xlNone Then
With .Interior
.ColorIndex = 6
.Pattern = xlSolid
End With
Else
With .Interior
.Pattern = xlNone
End With
End If
end with
End Sub

If you really meant that you didn't want to have the sub run when you clicked on
the checkbox, then don't use checkbox2_click inside your worksheet module.

Move your code to a general module and call it something else. (Actually, you
could use the same name--but it might get confusing why it's in a general module
in a week or two.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top