I'm trying to obtain the value for Teller from an userform in my module. Here's my userform code:
Private Sub UserForm_Initialize()
Dim LastRow As Long
Dim i As Long
Dim Teller As Long
Dim chkBox As MSForms.CheckBox
Teller = 1
LastRow = Worksheets("Sheet").Cells(Rows.Count, 1).End(xlUp).Row
For i = 1 To LastRow
If Worksheets("Sheet").Cells(i, 1).Value = Worksheets("Sheet").Range("S1").Value Then
Set chkBox = Me.Controls.Add("Forms.CheckBox.1", "CheckBox_" & Teller)
chkBox.Caption = Worksheets("Sheet").Cells(i, 9).Value
chkBox.Left = 5
chkBox.Top = 25 + ((Teller - 1) * 20)
Teller = Teller + 1
End If
Next i
End Sub
And my module code:
Dim p As Long
Dim x As String
With UserForm
.Show
For p = 1 To .Teller
x= .Controls("CheckBox_" & p).Caption
MsgBox (x)
Next p
End
End With
UserForm.Teller won't give me the value of Teller. How do I get this?
telleris declared as private to the userform, so modules will not be able to read it. You can declare teller as public in a module, which will give you the ability to read it from other modules.