mercredi 8 septembre 2021

Excel VBA: Looping through all checkboxes on all pages of a userform

I am currently having an issue with my code that is supposed to loop through every checkbox of every page of a userform. The code that I have so far works, but only if my userform consists of just one page. As soon as my userform consits of multiple pages with checkboxes I get the run-time error 438: 'object doesnt support this method or property'.

This is my code:

Private Sub CommandButton1_Click()

  For Each xcontrol In Me.Controls

   If TypeName(xcontrol) = "CheckBox" And xcontrol.Value = True Then

    Dim lRow As Integer

    lRow = Cells(Rows.Count, 1).End(xlUp).Row+1

    Cells(lRow, 1).Value = xcontrol.Caption

   End If

  Next xcontrol

End Sub

the error message highlights the third line:

If TypeName(xcontrol) = "CheckBox" And xcontrol.Value = True Then



Aucun commentaire:

Enregistrer un commentaire