Thomas Dolon
Thomas Dolon

Reputation: 1

excel-vba multiple checkbox

im currently working on a project to automate memo.

i want to know how can multiple checkbox result can show to a single checkbox

please see example below screenshot enter image description here If I check the checkbox dog, cat and mouse, it should show in the textbox as dog, cat, mouse respectively or, if i uncheck one of the checkbox it wont show in textbox

thank you so much for your help

Upvotes: 0

Views: 82

Answers (1)

Storax
Storax

Reputation: 12177

The straightforward solution would be to put the following code into the module of the userform

Option Explicit
Private petsChecked(1 To 3) As String
Private Sub chCat_Click()
    checkPets chCat, 1, "Cat"
    fillChecked
End Sub

Private Sub chDog_Click()
    checkPets chDog, 2, "Dog"
    fillChecked
End Sub

Private Sub chMouse_Click()
    checkPets chMouse, 3, "Mouse"
    fillChecked
End Sub
Private Sub checkPets(fill As Boolean, pos As Byte, petName As String)
    If fill Then
        petsChecked(pos) = petName
    Else
        petsChecked(pos) = ""
    End If
End Sub
Private Sub fillChecked()
    TextBox1 = Join(petsChecked, " ")
    ' ListBox1.List = petsChecked   '  <= this is the code for a listbox
End Sub

Another advanced solution would be to use a class module for the check boxes similar to this example

Upvotes: 1

Related Questions