Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 120
Default Select one checkbox to Deselect another

use option buttons instead?
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 120
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,117
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,117
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Deselect B1 & move curser to select A1 aussiegirlone Excel Discussion (Misc queries) 2 July 10th 09 03:00 AM
select all, deselect these md[_2_] Excel Discussion (Misc queries) 1 March 2nd 08 03:08 PM
How to select and deselect rows in Excel Gallant Excel Discussion (Misc queries) 1 July 4th 05 01:59 AM
How can I select / deselect columns for printing TomH Excel Programming 1 April 28th 05 08:40 PM
Select all/Deselect all button in a form Stuart[_5_] Excel Programming 2 August 6th 03 07:55 PM


All times are GMT +1. The time now is 06:40 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"