Forms control checkboxes on charts

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I have 2 checkboxes (forms) on a chart. I would like to have just one
checkbox checked at anytime. I know a radiobutton would do the same but I
need only 2 checkboxes since they don't fall into a single category. What do
I have to do to achieve this? I tried to group them but it doesn't help. How
do I write code for this? Also is it possible to change the names of these
checkboxes from checkboxN to something else?

Please help.

Regards,
Ram
 
Hi,

Please help. Still have no idea about how to proceed.

Regards,
Ra
 
How about:

Option Explicit
Sub cbx_click()

Dim CBX As CheckBox
Dim OtherCBX As CheckBox

With ActiveChart
Set CBX = .CheckBoxes(Application.Caller)
If LCase(CBX.Name) = "check box 1" Then
Set OtherCBX = .CheckBoxes("check box 2")
Else
Set OtherCBX = .CheckBoxes("check box 1")
End If
End With

If CBX.Value = xlOn Then
OtherCBX.Value = xlOff
End If

End Sub


You can change the name of a checkbox by selecting it (sometimes rightclicking
on it is easier) and then typing the new name into the namebox (to the left of
the formulabar). Remember to hit enter when you're done typing.

But if you change the names of the checkbox, you'll have to change the code. I
used "check box 1" and "check box 2".
 
And I allowed both checkboxes to be unchecked.

Dave said:
How about:

Option Explicit
Sub cbx_click()

Dim CBX As CheckBox
Dim OtherCBX As CheckBox

With ActiveChart
Set CBX = .CheckBoxes(Application.Caller)
If LCase(CBX.Name) = "check box 1" Then
Set OtherCBX = .CheckBoxes("check box 2")
Else
Set OtherCBX = .CheckBoxes("check box 1")
End If
End With

If CBX.Value = xlOn Then
OtherCBX.Value = xlOff
End If

End Sub

You can change the name of a checkbox by selecting it (sometimes rightclicking
on it is easier) and then typing the new name into the namebox (to the left of
the formulabar). Remember to hit enter when you're done typing.

But if you change the names of the checkbox, you'll have to change the code. I
used "check box 1" and "check box 2".
 
Assign this code to both checkboxes.

Sub cbox_Click()
Dim sName As String, cbox1 As CheckBox
Dim cbox2 As CheckBox
sName = Application.Caller
If LCase(sName) = "check box 1" Then
Set cbox2 = ActiveChart.CheckBoxes("Check box 2")
Else
Set cbox2 = ActiveChart.CheckBoxes("Check box 1")
End If
Set cbox1 = ActiveChart.CheckBoxes(sName)
If cbox1 = xlOn Then
cbox2 = xlOff
Else
' comment out if both can be unchecked.
cbox2 = xlOn
End If
End Sub


if you select the checkbox, then you can rename it in the namebox.
(highlight the current name and type in a new name. You would need to
adjust the code above to match the names.
 
Assign this code to both checkboxes.

Sub cbox_Click()
Dim sName As String, cbox1 As CheckBox
Dim cbox2 As CheckBox
sName = Application.Caller
If LCase(sName) = "check box 1" Then
Set cbox2 = ActiveChart.CheckBoxes("Check box 2")
Else
Set cbox2 = ActiveChart.CheckBoxes("Check box 1")
End If
Set cbox1 = ActiveChart.CheckBoxes(sName)
If cbox1 = xlOn Then
cbox2 = xlOff
Else
' comment out if both can be unchecked.
cbox2 = xlOn
End If
End Sub


if you select the checkbox, then you can rename it in the namebox.
(highlight the current name and type in a new name. You would need to
adjust the code above to match the names.
 
Hi Dave and Tom,

Thanks a lot for that help. I was able to achieve what I wanted t
without any problems. BTW what useful purpose does it serve to grou
checkboxes?

Regards,
Ra
 
Prettiness???

Kind of shows what's related--like Tools|Option|View tab.
 

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

Back
Top