Controlling Radio Button

R

rk0909

All,

Is it possible to NOT run a code associated with a radio button when the
linked cell is manually or programatically changed to TRUE.

In other words, I am trying to trigger a code when the user hits the radio
button, but in another scenario I want the to change the linked cell property
to TRUE while not running the associated code.

thanks much for your help.

R
 
D

Dave Peterson

I bet you've seen application.enableevents in event code.

That's the setting will allow the developer to tell excel to stop looking for
things that would cause an event to fire.

You can do the same kind of thing if you keep track yourself.

I used a commandbutton placed on a worksheet (Sheet1). This was the code in the
worksheet module:

Option Explicit
Private Sub CheckBox1_Change()
If BlkProc = True Then
Exit Sub
End If
MsgBox Me.CheckBox1.Value
End Sub


Then I added this to a General module (not behind a worksheet and not behind
ThisWorkbook):

Option Explicit
Public BlkProc As Boolean
Sub testme()
With Worksheets("sheet1").Range("a1")
BlkProc = True
.Value = Not .Value
BlkProc = False
End With
End Sub


The _Change event (or _Click if you use that) still fires, but the first thing
the code does is look to see if it should continue or just exit.
 
C

Chip Pearson

Assuming that you are using a radio button from the Controls command
bar, not the Forms command bar and the linked cell is L13, both on
Sheet1, use the following code in the Sheet1 code module:

Public IgnoreEvent As Boolean
Private Sub OptionButton1_Click()
If IgnoreEvent = True Then
Exit Sub
End If
'''''''
' your normal code goes here
''''''''
End Sub

Then, in a regular code module, use

Sub AAA()
Sheet1.IgnoreEvent = True
Range("L13").Value = True
Sheet1.IgnoreEvent = False
End Sub

The IgnoreEvent = True will cause the OptionButton1_Click event code
to immediately exit without doing any work, then L13 is set to True
which checks the radio button, and then you set IgnoreEvent back to
False for normal behavior.

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)
 

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