I'm trying to do a loop based on the name of my TextBox. For example, I have for TextBox the following names txtRA1, txtRA2, txtRA3, txtRA4. I want to put an i as integer in the local of their number. How can I do that? Is there any way? The code is next: ---> "Userform3.txtRA&i.Text"
Private Sub btGerarRelatorio_Click()
Dim tWB As Workbook, aWB As Workbook
Dim i As Integer, k As Integer, nr As Integer, v As Integer
Dim A() As String, filename As String
Set tWB = ThisWorkbook
filename = Auxiliar.Range("bd_alunos")
Workbooks.Open filename, Password:="***"
Set aWB = ActiveWorkbook
ReDim A(6) As String
aWB.Worksheets("BD_Alunos").Activate
nr = aWB.Worksheets("BD_Alunos").Application.WorksheetFunction.CountA(Columns("B:B")) - 1
For i = 1 To 4
For k = 1 To nr
If aWB.Worksheets("BD_Alunos").Range("B5").Offset(k, 1) = ***UserForm3.txtRA&i.text*** Then
A(1) = aWB.Worksheets("BD_Alunos").Range("B5").Offset(k, 2)
A(2) = aWB.Worksheets("BD_Alunos").Range("B5").Offset(k, 3)
A(3) = aWB.Worksheets("BD_Alunos").Range("B5").Offset(k, 47)
A(4) = aWB.Worksheets("BD_Alunos").Range("B5").Offset(k, 48)
A(5) = aWB.Worksheets("BD_Alunos").Range("B5").Offset(k, 49)
A(6) = aWB.Worksheets("BD_Alunos").Range("B5").Offset(k, 50)
v = 1
End If
If verific = 1 Then
Exit For
End If
Next k
Next i
aWB.Close Savechanges:=True
End Sub
Try Userform3.Controls("txtRA"&i).Text