MrExcel Publishing
Your One Stop for Excel Tips & Solutions

VB Tick box


Posted by Paul on April 16, 2001 1:28 PM

Is it possible to get a macro to display a window containing 2 or tick boxes? and do the following, when one is ticked and Ok is pressed. Could it then run a specific macro and if a different is ticked run a different macro.

Thanks


Posted by Dave Hawley on April 16, 2001 1:51 PM

Hi Paul

Yes it is possible, you would use a UserForm with 2 Option buttons or Checkboxes and a CommandButton


Dave
OzGrid Business Applications

Posted by Paul on April 16, 2001 2:24 PM

How would I go about doing this?

How would I go about doing this?

Thnaks

Posted by Dave Hawley on April 16, 2001 4:01 PM

Re: How would I go about doing this?

1. Push Alt+F11 and go to Insert>UserForm

2. From the Toolbox that also appears select a OptionButton and place it on your form. Do the same again. Then place a CommandButton on the Form.

3. Right click on each of the Controls to access their Properties Window. This is where you can change the Caption etc.

4 Double click the CommandButton and place in this code:


Private Sub CommandButton1_Click()

If OptionButton1.Value = True Then
Run "MyMarco1"
If OptionButton2.Value = True Then
Run "MyMacro2"
End If
End If

End Sub

change to suit.

5. Go back to your Form and place another CommandButton on and change it's caption to "Cancel"

6. Double click it and place in this code:

Private Sub CommandButton2_Click()
Unload Me

End Sub

7. In a normal Module place this code:

Sub ShowMyform
Userform1.Show
End Sub

Attach this code to a button or shortcut key.


8. Run the "ShowMyform" macro

Dave

OzGrid Business Applications