vendredi 26 mars 2021

VBA Create array with userform items

I have a a list of checkbox in userform. I would like to create a code that is more efficient that the following one :

If checkbox1.value = true
Then Range("A1").value = 100
End if
If checkbox2.value = true
Then Range("A2").value = 200
End if
If checkbox3.value = true
Then Range("A3").value = 300
End if

The problem is that I have 40 checkbox and I would like to create something that says: in my list of checkbox, if it is true then add in my range A1. I'm not sure how to proceed but I tried this:

Dim Element as variant
For each element in MyList
If element.value = true Then 
For i = 1 to NumberOfTrueElement
Range("A" & i + 1).value = Mylist(i)
Next i
End if
Next

Mylist is the frame of all my checkboxes. Please help me if you have a hint.

Aucun commentaire:

Enregistrer un commentaire