How to retrieve checkbox data?
Solved
Mr Boushido
Posted messages
6
Status
Member
-
eriiic Posted messages 24581 Registration date Status Contributor Last intervention -
eriiic Posted messages 24581 Registration date Status Contributor Last intervention -
Bonjour,
I'd like that when a user clicks or double-clicks (it doesn't matter) on a cell, a UserForm appears with about fifteen checkboxes, and a validate button that will retrieve the values of these checkboxes (but be careful, I don't want it to show True or False... see below) to display these values in that very cell (by the way, I'd like the cell to adjust based on the number of values).
The values look like this:
checkbox1 "Compliant"
checkbox2 "Non-compliant"
checkbox3 "Scratch"
checkbox4 "Deep scratch"
checkbox5 "etc..."
' '
' '
' '
Here's an example of my validate button that doesn't work (lol I'm just starting out)
Private Sub Validate_Click()
Dim i As Integer
For i = 1 To 14
If Me.CheckBox(i).Value = True Then
ActiveCell.Value = ActiveCell.Value & Me.CheckBox(i).Caption & ", "
End If
Next i
End Sub
Thank you for explaining how to do it.
Best regards.
I'd like that when a user clicks or double-clicks (it doesn't matter) on a cell, a UserForm appears with about fifteen checkboxes, and a validate button that will retrieve the values of these checkboxes (but be careful, I don't want it to show True or False... see below) to display these values in that very cell (by the way, I'd like the cell to adjust based on the number of values).
The values look like this:
checkbox1 "Compliant"
checkbox2 "Non-compliant"
checkbox3 "Scratch"
checkbox4 "Deep scratch"
checkbox5 "etc..."
' '
' '
' '
Here's an example of my validate button that doesn't work (lol I'm just starting out)
Private Sub Validate_Click()
Dim i As Integer
For i = 1 To 14
If Me.CheckBox(i).Value = True Then
ActiveCell.Value = ActiveCell.Value & Me.CheckBox(i).Caption & ", "
End If
Next i
End Sub
Thank you for explaining how to do it.
Best regards.
8 answers
Re,
hence my question Link (#3):
ActiveCell = CaseCoche.CheckBox(i).Value (even if the code is wrong) Since you have checkboxes, why write in only one cell???
an example of code to put in the VBA of the Userform: (here two checkboxes, but code to write for the other 12) writing Sheet1 A1 to A14 based on selection
Dim ValCheck(14)
Private Sub checkbox1_click()
If CheckBox1 Then
ValCheck(0) = "Compliant"
Else
ValCheck(0) = ""
End If
End Sub
Private Sub checkbox2_click()
If CheckBox2 Then
ValCheck(1) = "Non Compliant"
Else
ValCheck(1) = ""
End If
End Sub
Private Sub Validate_Click()
Dim i As Integer, point As Byte
With Worksheets("Sheet1")
point = 1
.Range("A1:A15").ClearContents
For i = 0 To 1 '14
If ValCheck(i) <> "" Then
.Range("A" & point) = ValCheck(i)
point = point + 1
End If
Next i
End With
'CaseCoche.Hide
End Sub
hence my question Link (#3):
ActiveCell = CaseCoche.CheckBox(i).Value (even if the code is wrong) Since you have checkboxes, why write in only one cell???
an example of code to put in the VBA of the Userform: (here two checkboxes, but code to write for the other 12) writing Sheet1 A1 to A14 based on selection
Dim ValCheck(14)
Private Sub checkbox1_click()
If CheckBox1 Then
ValCheck(0) = "Compliant"
Else
ValCheck(0) = ""
End If
End Sub
Private Sub checkbox2_click()
If CheckBox2 Then
ValCheck(1) = "Non Compliant"
Else
ValCheck(1) = ""
End If
End Sub
Private Sub Validate_Click()
Dim i As Integer, point As Byte
With Worksheets("Sheet1")
point = 1
.Range("A1:A15").ClearContents
For i = 0 To 1 '14
If ValCheck(i) <> "" Then
.Range("A" & point) = ValCheck(i)
point = point + 1
End If
Next i
End With
'CaseCoche.Hide
End Sub