Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Select one checkbox to Deselect another
I have five checkboxes from C7 to G7. I want the flow like this if I select
any one checkbox among those five the other four box should become unchecked automatically. Please help. |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Select one checkbox to Deselect another
use option buttons instead?
|
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Select one checkbox to Deselect another
I do not want to use the option button. I want to do the same with
checkboxes. Please tell me that it is possible or not. |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Select one checkbox to Deselect another
Yes, it's completely possible. You just have to add code to pick up
when the value of a checkbox changes and reset the other checkboxes. Theres loads of code samples on the web. |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Select one checkbox to Deselect another
if checkbox1.value = true then checkbox2.value = false checkbox3.value = false end if if checkbox2.value = true then checkbox1.value = false checkbox3.value = false end if if checkbox3.value = true then checkbox1.value = false checkbox2.value = false end if like that hth susan On May 19, 9:35*am, Keith74 wrote: Yes, it's completely possible. You just have to add code to pick up when the value of a checkbox changes and reset the other checkboxes. Theres loads of code samples on the web. |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
Select one checkbox to Deselect another
using control toolbox checkboxes, i put them within _click events
(when they get checked): Option Explicit Private Sub CheckBox1_Click() CheckBox2.Value = False CheckBox3.Value = False End Sub ========================== Private Sub CheckBox2_Click() CheckBox1.Value = False CheckBox3.Value = False End Sub ========================= Private Sub CheckBox3_Click() CheckBox1.Value = False CheckBox2.Value = False End Sub ========================= did one for each checkbox, as mentioned previously. hope it helps. susan On May 19, 1:06*pm, Susan wrote: if checkbox1.value = true then * *checkbox2.value = false * *checkbox3.value = false end if if checkbox2.value = true then * *checkbox1.value = false * *checkbox3.value = false end if if checkbox3.value = true then * *checkbox1.value = false * *checkbox2.value = false end if like that hth susan On May 19, 9:35*am, Keith74 wrote: Yes, it's completely possible. You just have to add code to pick up when the value of a checkbox changes and reset the other checkboxes. Theres loads of code samples on the web.- Hide quoted text - - Show quoted text - |
#7
Posted to microsoft.public.excel.programming
|
|||
|
|||
Select one checkbox to Deselect another
Here's one way. In VBA, go to the "Insert" menu, choose "Module", and paste
the following code in that module. '''''''''''''''''''''''''''''''''''''''''''''''''' '' '''''''''''''''''''''''''''''''''''''''''''''''''' '' Option Explicit Option Compare Text Dim ObjCollection As Collection Dim ChkCollection As Collection Sub Auto_Open() Dim WS As Excel.Worksheet Dim CKBox As CCheck Dim OleObj As Excel.OLEObject Set ObjCollection = New Collection Set ChkCollection = New Collection Set WS = ThisWorkbook.Worksheets("Sheet1") For Each OleObj In WS.OLEObjects With OleObj If TypeOf .Object Is MSForms.CheckBox Then If Not Application.Intersect(WS.Range("C7:G7"), .TopLeftCell) Is Nothing Then Set CKBox = New CCheck CKBox.AddCheckBox .Object CKBox.SetCollection ChkCollection ChkCollection.Add .Object ObjCollection.Add CKBox End If End If End With Next OleObj End Sub '''''''''''''''''''''''''''''''''''''''''''''''''' '' '''''''''''''''''''''''''''''''''''''''''''''''''' '' Then, in VBA, go to the "Insert" menu and choose "Class Module". Press F4 to bring up the "Properties" window and change the Name from "Class1" to "CCheck". In that class module, paste the following code: '''''''''''''''''''''''''''''''''''''''''''''''''' '' '''''''''''''''''''''''''''''''''''''''''''''''''' '' Option Explicit Option Compare Text Private WithEvents pChkBox As MSForms.CheckBox Private pCheckBoxes As Collection Private pIgnore As Boolean Private Sub Class_Initialize() Set pCheckBoxes = New Collection End Sub Friend Sub AddCheckBox(CHK As MSForms.CheckBox) Set pChkBox = CHK End Sub Friend Sub SetCollection(C As Collection) Set pCheckBoxes = C End Sub Private Sub pChkBox_Click() Dim N As Long If pChkBox.Value = 0 Then Exit Sub ' unchecked. get out. End If If pIgnore = True Then Exit Sub ' internal event. get out. End If On Error GoTo ErrH: pIgnore = True With pCheckBoxes For N = 1 To .Count If .Item(N).Caption < pChkBox.Caption Then .Item(N).Value = 0 End If Next N End With ErrH: pIgnore = False End Sub '''''''''''''''''''''''''''''''''''''''''''''''''' '' '''''''''''''''''''''''''''''''''''''''''''''''''' '' Finally, run the Auto_Open procedure to initialize things. (This will run automatically when you open the workbook later.) The code makes all of the check box objects whose Top Left Cell is in the range C7:G7 on Sheet1 mutually exclusive. Checking one will uncheck all the others. Check boxes that are not within C7:G7 are not affected by the code. You can have as many checkboxes as you want, name those checkboxes anything you want and the code will continue to work. Note, though, that if you add checkboxes or change their names, you'll need to run the Auto_Open procedure again. -- Cordially, Chip Pearson Microsoft Most Valuable Professional Excel Product Group Pearson Software Consulting, LLC www.cpearson.com (email on web site) "geniussamu" wrote in message ... I have five checkboxes from C7 to G7. I want the flow like this if I select any one checkbox among those five the other four box should become unchecked automatically. Please help. |
#8
Posted to microsoft.public.excel.programming
|
|||
|
|||
Select one checkbox to Deselect another
My code assumed that all the check boxes have distinct captions. If this is
not the case, change the line of code in the Class Module from If .Item(N).Caption < pChkBox.Caption Then to If Not .Item(N) Is pChkBox Then -- Cordially, Chip Pearson Microsoft Most Valuable Professional Excel Product Group Pearson Software Consulting, LLC www.cpearson.com (email on web site) "Chip Pearson" wrote in message ... Here's one way. In VBA, go to the "Insert" menu, choose "Module", and paste the following code in that module. '''''''''''''''''''''''''''''''''''''''''''''''''' '' '''''''''''''''''''''''''''''''''''''''''''''''''' '' Option Explicit Option Compare Text Dim ObjCollection As Collection Dim ChkCollection As Collection Sub Auto_Open() Dim WS As Excel.Worksheet Dim CKBox As CCheck Dim OleObj As Excel.OLEObject Set ObjCollection = New Collection Set ChkCollection = New Collection Set WS = ThisWorkbook.Worksheets("Sheet1") For Each OleObj In WS.OLEObjects With OleObj If TypeOf .Object Is MSForms.CheckBox Then If Not Application.Intersect(WS.Range("C7:G7"), .TopLeftCell) Is Nothing Then Set CKBox = New CCheck CKBox.AddCheckBox .Object CKBox.SetCollection ChkCollection ChkCollection.Add .Object ObjCollection.Add CKBox End If End If End With Next OleObj End Sub '''''''''''''''''''''''''''''''''''''''''''''''''' '' '''''''''''''''''''''''''''''''''''''''''''''''''' '' Then, in VBA, go to the "Insert" menu and choose "Class Module". Press F4 to bring up the "Properties" window and change the Name from "Class1" to "CCheck". In that class module, paste the following code: '''''''''''''''''''''''''''''''''''''''''''''''''' '' '''''''''''''''''''''''''''''''''''''''''''''''''' '' Option Explicit Option Compare Text Private WithEvents pChkBox As MSForms.CheckBox Private pCheckBoxes As Collection Private pIgnore As Boolean Private Sub Class_Initialize() Set pCheckBoxes = New Collection End Sub Friend Sub AddCheckBox(CHK As MSForms.CheckBox) Set pChkBox = CHK End Sub Friend Sub SetCollection(C As Collection) Set pCheckBoxes = C End Sub Private Sub pChkBox_Click() Dim N As Long If pChkBox.Value = 0 Then Exit Sub ' unchecked. get out. End If If pIgnore = True Then Exit Sub ' internal event. get out. End If On Error GoTo ErrH: pIgnore = True With pCheckBoxes For N = 1 To .Count If .Item(N).Caption < pChkBox.Caption Then .Item(N).Value = 0 End If Next N End With ErrH: pIgnore = False End Sub '''''''''''''''''''''''''''''''''''''''''''''''''' '' '''''''''''''''''''''''''''''''''''''''''''''''''' '' Finally, run the Auto_Open procedure to initialize things. (This will run automatically when you open the workbook later.) The code makes all of the check box objects whose Top Left Cell is in the range C7:G7 on Sheet1 mutually exclusive. Checking one will uncheck all the others. Check boxes that are not within C7:G7 are not affected by the code. You can have as many checkboxes as you want, name those checkboxes anything you want and the code will continue to work. Note, though, that if you add checkboxes or change their names, you'll need to run the Auto_Open procedure again. -- Cordially, Chip Pearson Microsoft Most Valuable Professional Excel Product Group Pearson Software Consulting, LLC www.cpearson.com (email on web site) "geniussamu" wrote in message ... I have five checkboxes from C7 to G7. I want the flow like this if I select any one checkbox among those five the other four box should become unchecked automatically. Please help. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Deselect B1 & move curser to select A1 | Excel Discussion (Misc queries) | |||
select all, deselect these | Excel Discussion (Misc queries) | |||
How to select and deselect rows in Excel | Excel Discussion (Misc queries) | |||
How can I select / deselect columns for printing | Excel Programming | |||
Select all/Deselect all button in a form | Excel Programming |