如何循环文本框(userform1.textbox1到userform1.textbox2)

时间:2013-08-22 18:05:17

标签: vba

如何指定每个For / next周期,文本框的编号应增加一,从Userform1.Textbox1增加到Userform1.Textbox2,依此类推工作簿中的每个工作表?

我正在尝试“UserForm1.TextBox& i”和“i = i + 1” 但是我收到了语法错误。

有什么建议吗?

Application.ScreenUpdating = False
SheetName = ActiveSheet.Name
FindString = InputBox("Enter the case number to search for:")

i = 1

For Each ws In Worksheets
    If ws.Name Like "lang*" Then
        With ws

            If Trim(FindString) <> "" Then
                With Sheets(1).Range("A:A")
                    Set Rng = .Find(What:=FindString, _
                                    After:=.Cells(.Cells.Count), _
                                    LookIn:=xlValues, _
                                    LookAt:=xlWhole, _
                                    SearchOrder:=xlByRows, _
                                    SearchDirection:=xlNext, _
                                    MatchCase:=False)
                    If Not Rng Is Nothing Then

            UserForm1.TextBox & i = ActiveSheet.Name & "     " & _
            Rng.Offset(0, 2).Value & "     " & _

            i = i + 1

                    Else: GoTo NotFound
                    End If
                End With
            End If

        End With
    End If
Next ws

Sheets(SheetName).Activate
Application.ScreenUpdating = True
UserForm1.Show

2 个答案:

答案 0 :(得分:1)

UserForm1.Controls("TextBox" & i)

答案 1 :(得分:-1)

var control = this.Controls.Find("TextBox" + i, true).FirstOrDefault();

if (control != null)
{
    //do something                
}