Excel 如何在i=1到12和while';txt#U Case#U编号(i).Text';有价值吗?

Excel 如何在i=1到12和while';txt#U Case#U编号(i).Text';有价值吗?,excel,vba,Excel,Vba,我已经创建了一个搜索用户表单,它需要在搜索案例编号时显示可能有部分重复信息的记录。然后我对该记录进行更改,并用新信息更新工作表。 我想做的就是这样: While i = 1 to 12 .Cells(RowFound(i), "A") = txt_Case_Number(i).Text .Cells(RowFound(i), "B") = cmboCase_Status(i).Text 下面是我所拥有的,并希望它能像上面所展示的那样开始 Private Sub cmdMakeE

我已经创建了一个搜索用户表单,它需要在搜索案例编号时显示可能有部分重复信息的记录。然后我对该记录进行更改,并用新信息更新工作表。 我想做的就是这样:

While i = 1 to 12
    .Cells(RowFound(i), "A") = txt_Case_Number(i).Text
    .Cells(RowFound(i), "B") = cmboCase_Status(i).Text
下面是我所拥有的,并希望它能像上面所展示的那样开始

Private Sub cmdMakeEdit1_Click()        
    With Sheets("Sheet1")
        .Cells(RowFound1, "A") = txt_Case_Number1.Text
        .Cells(RowFound1, "B") = cmboCase_Status1.Text
        .Cells(RowFound1, "C") = txtDate_of_Seizure1.Text
        .Cells(RowFound1, "D") = txtSeizure_Type1.Text
        .Cells(RowFound1, "L") = TxtCurr1.Text
        .Cells(RowFound1, "N") = TxtCurr_Dep1.Text
        .Cells(RowFound1, "S") = txtPDH_CourtDate1.Text
        .Cells(RowFound1, "U") = txtDays_PDH_Courtdate1.Text
        .Cells(RowFound1, "V") = txtPC_Received1.Text
        .Cells(RowFound1, "W") = txtDays_464_Filing1.Text
        .Cells(RowFound1, "Y") = txt464_Filed1.Text
        .Cells(RowFound1, "Z") = txtDays_Article36_Filing1.Text
        .Cells(RowFound1, "AA") = txtArticle_36_Due1.Text
        .Cells(RowFound1, "AB") = txtArticle_36_Filed1.Text
        .Cells(RowFound1, "AC") = txtDeclaration_Letter1.Text
        .Cells(RowFound1, "AE") = txtCurr_Sent_ISP1.Text
        .Cells(RowFound1, "AF") = txtAmount_Sent1.Text
        .Cells(RowFound1, "AG") = txtYear1.Text
        .Cells(RowFound1, "AH") = cmbo_Make1.Text
        .Cells(RowFound1, "AI") = cmbo_Model1.Text
        .Cells(RowFound1, "AJ") = cmbo_Color1.Text
        .Cells(RowFound1, "AK") = txtPlate1.Text
        .Cells(RowFound1, "AL") = txtVIN1.Text
        .Cells(RowFound1, "AM") = txtLEADS1.Text
        .Cells(RowFound1, "AN") = txtOwners_Name1.Text
        .Cells(RowFound1, "AQ") = txtLien1.Text
        .Cells(RowFound1, "AT") = cmbLocation1.Text
        .Cells(RowFound1, "AU") = txtFull_Name1.Text
        .Cells(RowFound1, "AV") = txtItem_Desc1.Text
        .Cells(RowFound1, "AW") = txtItem_Model1.Text
        .Cells(RowFound1, "AX") = txtItem_Serial1.Text
        .Cells(RowFound1, "AY") = txtOther_Info1.Text
        .Cells(RowFound1, "AZ") = txtItem_PickedUP1.Text
        .Cells(RowFound1, "BA") = txt_Search1_Type.Text
您可能需要:

i = 1
While (txt_Case_Number(i).Text <> "" And i <= 12)
    '...
    i = i + 1
Wend
i=1

While(txt_Case_Number(i).Text“”和i循环表单控件元素的唯一方法之一是初始化控件,并在每个
循环的
中使用它。然后可以在If语句中验证控件的名称或类型,例如

Dim ctl As Control

For Each ctl in Me.Controls '<-assuming your button is on the form the rest of the controls are
    If TypeName(ctl) = "TextBox" or TypeName(ctl) = "ComboBox" Then
        'Do Stuff'
    End If
Next ctl
Dim ctl作为控件
对于Me.Controls中的每个ctl,
Controls(“txt\u Case\u Number”&i)。