首页 > 解决方案 > 我将如何使用用户窗体中的 If 语句,如果单元格与另一个单元格匹配,它将结果添加到特定字段/行?

问题描述

我的大部分代码都可以正常工作,但是,当我进入验证表单时,用户表单无法正常工作。我使用的表格允许用户在 AA 列中输入工作编号,在 AC 列中输入数量。我在 A 列中保留一份工作列表。当用户使用该按钮时,它将自动填充 AA 到 AD 列,我正在寻找完成此操作后,它将检查工作编号是否存在于 A 列中以及是否存在然后在 D 列的同一行中,它将添加刚刚输入的数量。在后台我有一段代码将自动计算并在 D 列中增加

Private Sub CommandButton1_Click()
whichSheet = PartNoTxtBox.Value
If whichSheet = "" Then
MsgBox "You didn't specify a Part Number"
Exit Sub
End If
Worksheets(whichSheet).Activate
    If Me.PartNoTxtBox = "" Then GoTo MoreInfo
    If Me.AddJobNoTxtBox = "" Then GoTo MoreInfo
    If Me.AddShipperNoTxtBox = "" Then GoTo MoreInfo
    If Me.AddQtyTxtBox = "" Then GoTo MoreInfo
    If Me.AddDate = "" Then GoTo MoreInfo
''LastRow
    eRow = Cells(Rows.Count, "AA").End(xlUp).Offset(1, 27).Row
        Cells(eRow, 27) = AddJobNoTxtBox.Text
        Cells(eRow, 28) = AddShipperNoTxtBox.Text
        Cells(eRow, 29) = AddQtyTxtBox.Text
        Cells(eRow, 30) = AddDate.Text
       If AddJobNoTxtBox.Value = Cells(eRow, 1) Then
         Cells(eRow, 4) = AddQtyTxtBox.Text
        End If
 Unload UserForm1
Exit Sub
MoreInfo:
    MsgBox "More information required."

End Sub

问题位于 If AddJobNoTxtBox.Value=Cells... 任何方向都会有所帮助。

标签: excelvba

解决方案


推荐阅读