NessPJ
Active Member
- Joined
- May 10, 2011
- Messages
- 413
- Office Version
-
- 365
I have a question about Dynamic Objects on my Userform.
I use this code to generate a list of checkboxes (and output their generated name to a cell). Now i would like to use a piece of code inside my UserForm_Activate module to select one of these Checkboxes
after it has been generated. For some reason Excel is not letting me and i keep getting an Error 'Object required'.
Can anyone please help me and tell me if i am doing something wrong?
This is the code i use for generating the dynamic checkboxes:
I use this code to generate a list of checkboxes (and output their generated name to a cell). Now i would like to use a piece of code inside my UserForm_Activate module to select one of these Checkboxes
after it has been generated. For some reason Excel is not letting me and i keep getting an Error 'Object required'.
Can anyone please help me and tell me if i am doing something wrong?
This is the code i use for generating the dynamic checkboxes:
Rich (BB code):
Option Explicit
Public MutDatum, MutTijd, MutWeek, MutDag As String
Public MutDienst, MutTechnieker, MutTRow, MutTBox, MutActiviteit, MutTijdEenheden, MutOmschrijving, MutVervolgActie, MutVervolgActieCode As String
Private Sub UserForm_Activate()
Dim OmschrijvingWaarde, LastRowTechnieker, LastRowActiviteit, LastRowTag As String
Dim RegelnrRij, RegelnrGevonden As String
Dim curColumn As Long
Dim i As Long
Dim chkBox As MSForms.CheckBox
Dim Optionbutton As MSForms.Optionbutton
LastRowTechnieker = ThisWorkbook.Sheets("Masterdata").Range("B31").End(xlUp).Row
InputBox RegelnrRij
'Lijst met Technieker Checkboxes wordt dynamisch opgebouwd.
curColumn = 3 'Set your column index here
For i = 5 To LastRowTechnieker
Set chkBox = Me.Controls.Add("Forms.CheckBox.1", "CheckBox_" & (i - 4))
chkBox.Caption = ThisWorkbook.Sheets("Masterdata").Cells(i, curColumn).Value
chkBox.Left = 12
chkBox.Top = 8 + ((i - 4) * 16)
chkBox.GroupName = "Technieker"
ThisWorkbook.Sheets("Masterdata").Range("E" & i) = chkBox.Name
Next i
i = 0
MutTechnieker = ThisWorkbook.Sheets("Data Invoer").Range("AD" & RegelnrRij)
MutTRow = Zoeken(MutTechnieker, "Masterdata", "C31", "C")
MutTBox = ThisWorkbook.Sheets("Masterdata").Range("E" & MutTRow).Value
MsgBox Me.MutTBox.Value
End Sub
Public Function Zoeken(ZoekWaarde, ZoekSheet, LaatsteCellVoorZoeken, KolomVoorZoeken As String)
'De volgende routine creeërt een functie en zoekt een ingegeven string van onderen naar boven in de tabel (zodat de meest recente wordt gevonden).
'Vervolgens wordt het Regelnummer (Rownumber) teruggemeld als gevonden waarde.
Dim StringRowNumber As Integer, LaatsteCellZoekVeld, code As String
LaatsteCellZoekVeld = ThisWorkbook.Sheets(ZoekSheet).Range(LaatsteCellVoorZoeken, ThisWorkbook.Sheets(ZoekSheet).Range(LaatsteCellVoorZoeken).End(xlUp)).Row
If ZoekWaarde = "" Then GoTo StopMetZoeken
For StringRowNumber = LaatsteCellZoekVeld To 1 Step -1
code = ThisWorkbook.Sheets(ZoekSheet).Range(KolomVoorZoeken & StringRowNumber)
If code = ZoekWaarde Then
Zoeken = StringRowNumber
Exit For
End If
Next
StopMetZoeken:
End Function