Running Check box code after Command button Click

Running Check box code after Command button Click

Post by Todd » Thu, 16 Sep 2004 22:19:24


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
 
 
 

Running Check box code after Command button Click

Post by Dave Peter » Fri, 17 Sep 2004 06:46:28

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.)





--

Dave Peterson
XXXX@XXXXX.COM