Tim_Excel_
Well-known Member
- Joined
- Jul 12, 2016
- Messages
- 512
Hi Forum,
I've written a piece of code that looks in a column and places all unique values in seperate textboxes in a userform.
The next step would be referring to these textboxes in the userform code. Whatever I try however (Userform4.Textbox("box1").Value, or Userform.Textbox1.Value), nothing actually returns the values of the textboxes in the userform. How do I refer to the textboxes?
I've written a piece of code that looks in a column and places all unique values in seperate textboxes in a userform.
The next step would be referring to these textboxes in the userform code. Whatever I try however (Userform4.Textbox("box1").Value, or Userform.Textbox1.Value), nothing actually returns the values of the textboxes in the userform. How do I refer to the textboxes?
Code:
Public Sub ytj()
Dim NewBox As MSForms.TextBox
With Workbooks("0700.0006.000.21_01_01").Worksheets(3)
k = 0
l = 0
For i = 2 To .Cells(.Rows.Count, "A").End(xlUp).Row
If Left(Cells(i, 1).Value, 4) <> "" And Left(Cells(i, 1).Value, 4) <> Left(Cells(i - 1, 1).Value, 4) Then
Set NewBox = UserForm4.Controls.Add("Forms.textbox.1")
With NewBox
If i > 2 Then 'the if statement makes sure the first box is placed 30 from the top, and the next boxes 30 + 25 * k
.Name = "box" & k & ""
.Top = 30 + 25 * k
.Left = 10
.Locked = True
k = k + 1
Else
.Name = "box" & k & ""
.Top = 30
.Left = 10
.Locked = True
End If
NewBox.Value = Left(Cells(i, 1).Value, 4)
End With
Set NewBox = UserForm4.Controls.Add("Forms.textbox.1") 'another set of boxes on the right of the other boxes
With NewBox
If i > 2 Then
.Name = "boxinvul" & k & ""
.Top = 30 + 25 * l
.Left = 160
l = l + 1
Else
.Name = "boxinvul" & k & ""
.Top = 30
.Left = 160
End If
End With
End If
Next i
UserForm4.Show vbModeless
End With
End Sub