Rajesharihant
New Member
- Joined
- Jul 19, 2018
- Messages
- 5
Dear All,
I am trying since morning to work on this, I am creating an excel file which has 8 selections & i want users to select any 3. after 3 selections the rest of the selections shall disable. similarly, if user deselect any of the checked 3 options, the remaining options shall get enabled.
I am using activeX checkboxes and a VBA code int he excel - macro enabled worksheet.
My Idea is to just count the enabled checkboxes, and then compare the count (if higher then 3) to enable disable all checkboxes.
the issue i am facing, i guess is the checkboxes when i do a sum, it only works for 0 & 1. it doesn't go 2,3,4...
attached enter image description here is the code I have written
I am trying since morning to work on this, I am creating an excel file which has 8 selections & i want users to select any 3. after 3 selections the rest of the selections shall disable. similarly, if user deselect any of the checked 3 options, the remaining options shall get enabled.
I am using activeX checkboxes and a VBA code int he excel - macro enabled worksheet.
My Idea is to just count the enabled checkboxes, and then compare the count (if higher then 3) to enable disable all checkboxes.
the issue i am facing, i guess is the checkboxes when i do a sum, it only works for 0 & 1. it doesn't go 2,3,4...
attached enter image description here is the code I have written
Code:
Private Sub CheckBox1_Click()
Dim Raj1 As Integer
Dim Raj2 As Integer
Dim Raj3 As Integer
Dim Raj4 As Integer
Dim Raj5 As Integer
Dim Raj6 As Integer
Dim Raj7 As Integer
Dim Raj8 As Integer
Dim Total As Long
If CheckBox9.Enabled = True Then
Raj1 = CInt(CheckBox1.Value)
Raj2 = CInt(CheckBox2.Value)
Raj3 = CInt(CheckBox3.Value)
Raj4 = CInt(CheckBox4.Value)
Raj5 = CInt(CheckBox5.Value)
Raj6 = CInt(CheckBox6.Value)
Raj7 = CInt(CheckBox7.Value)
Raj8 = CInt(CheckBox8.Value)
Total = Raj1 + Raj2 + Raj3
End If
If Total > 2 Then
CheckBox6.Enabled = True
CheckBox7.Enabled = True
CheckBox8.Enabled = True
Else
CheckBox6.Enabled = False
CheckBox7.Enabled = False
CheckBox8.Enabled = False
End If
End Sub
Private Sub CheckBox2_Click()
Dim Raj1 As Integer
Dim Raj2 As Integer
Dim Raj3 As Integer
Dim Raj4 As Integer
Dim Raj5 As Integer
Dim Raj6 As Integer
Dim Raj7 As Integer
Dim Raj8 As Integer
Dim Total As Long
If CheckBox9.Enabled = True Then
Raj1 = CInt(CheckBox1.Value)
Raj2 = CInt(CheckBox2.Value)
Raj3 = CInt(CheckBox3.Value)
Raj4 = CInt(CheckBox4.Value)
Raj5 = CInt(CheckBox5.Value)
Raj6 = CInt(CheckBox6.Value)
Raj7 = CInt(CheckBox7.Value)
Raj8 = CInt(CheckBox8.Value)
Total = Raj1 + Raj2 + Raj3
End If
If Total = 1 Then
CheckBox6.Enabled = True
CheckBox7.Enabled = True
CheckBox8.Enabled = True
Else
CheckBox6.Enabled = False
CheckBox7.Enabled = False
CheckBox8.Enabled = False
End If
End Sub
Private Sub CheckBox3_Click()
Dim Raj1 As Integer
Dim Raj2 As Integer
Dim Raj3 As Integer
Dim Raj4 As Integer
Dim Raj5 As Integer
Dim Raj6 As Integer
Dim Raj7 As Integer
Dim Raj8 As Integer
Dim Total As Long
If CheckBox9.Enabled = True Then
Raj1 = CInt(CheckBox1.Value)
Raj2 = CInt(CheckBox2.Value)
Raj3 = CInt(CheckBox3.Value)
Raj4 = CInt(CheckBox4.Value)
Raj5 = CInt(CheckBox5.Value)
Raj6 = CInt(CheckBox6.Value)
Raj7 = CInt(CheckBox7.Value)
Raj8 = CInt(CheckBox8.Value)
Total = Raj1 + Raj2 + Raj3
End If
If Total = 1 Then
CheckBox6.Enabled = True
CheckBox7.Enabled = True
CheckBox8.Enabled = True
Else
CheckBox6.Enabled = False
CheckBox7.Enabled = False
CheckBox8.Enabled = False
End If
End Sub
Last edited by a moderator: