Jonnyoforem
New Member
- Joined
- May 22, 2015
- Messages
- 32
The following code is designed to find values on a worksheet and put those values into text boxes on a user form that will be opened at the end of the macro. The following code is an example of what I want and it works great.
It opens the userform, updatePackerForm, and the values I want are populated. However when I run the code like the following, it doesn't work
The code runs with no errors, but when it shows the userform, none of the values are in the textboxes. The textboxes are completely blank. I tried to Dim k As UserForm but then I get an error on the lilne
Any ideas? Thanks in advance for the help
Code:
Dim cCont As Control
Dim i As Integer
iRow = 30
i = 1
For Each cCont In updatePackerForm.Controls
If TypeName(cCont) = "TextBox" Then
cCont.Value = Worksheets("TrainingMatrix") _
.Range("Packer")(iRow, i).Value
End If
If TypeName(cCont) = "TextBox" Then
i = i + 1
End If
Next cCont
updatePackerForm.Show
It opens the userform, updatePackerForm, and the values I want are populated. However when I run the code like the following, it doesn't work
Code:
Dim cCont As Control
Dim i As Integer
Dim k As Variant
iRow = 30
i = 1
k = Cells(1, 6).Value 'This makes k = ' "updatePackerForm"
For Each cCont In VBA.UserForms.Add(k).Controls
If TypeName(cCont) = "TextBox" Then
cCont.Value = Worksheets("TrainingMatrix") _
.Range("Packer")(iRow, i).Value
End If
If TypeName(cCont) = "TextBox" Then
i = i + 1
End If
Next cCont
updatePackerForm.Show
The code runs with no errors, but when it shows the userform, none of the values are in the textboxes. The textboxes are completely blank. I tried to Dim k As UserForm but then I get an error on the lilne
Code:
k = Cells(1, 6).Value
Any ideas? Thanks in advance for the help