0

我在 vba 中自学成才,目前正在为我的公司构建一个基于表单的库存控制系统,将材料转换为定制尺寸。由于业务的定制性质取决于客户、使用的基材尺寸等。在使用基材后,可能会有无数不同的边角料或成品入库。因此,如果不实际滚动并查找它,就很难知道该产品是否已经存在于数据库 (FinPriceList) 中。因此,我正在寻找一种方法来检查产品是否存在于表 FinPriceList(分别为列 A、B、C 和 D)中,使用 vba 交叉引用来自组合框产品组(FinProdGroup)、产品类别“FinProdCat”的输入,产品描述“FinProdDesc”和文本框产品尺寸“

我目前的尝试如下,因此任何帮助将不胜感激:

Sub VerifyStock()
Const DQTE = """"

Dim criteria1 As String
Dim criteria2 As String
Dim criteria3 As String
Dim criteria4 As String
Dim evalStr As String
Dim prodCode As Variant

criteria1 = FinProdIn.FinProdGroupIn.Value 'combobox1 from userform
criteria2 = FinProdIn.FinProdCatIn.Value   'combobox2 from userform
criteria3 = FinProdIn.FinProdDescIn.Value  'combobox3 from userform
criteria4 = FinProdIn.FinProdSizeIn.Value  'combobox4 from userform
evalStr = "INDEX(FinishedPriceList,MATCH(" & DQTE & criteria1 & DQTE & "&" & DQTE & criteria2 & DQTE & "&" & DQTE & criteria3 & DQTE & "&" & DQTE & criteria4 & DQTE & ",FinPriceList!$A:$A&FinPriceList!$B:$B&FinPriceList!$C:$C&FinPriceList!$D:$D,0))"
prodCode = Evaluate(evalStr)

If VarType(prodCode) = vbError Then
    MsgBox "Not Found! Would you like to add new product to stock list?", vbYesNo
    If Response = vbNo Then
        MsgBox "Cancelled", vbInformation
        Unload FinProdIn
    Else
    Call ModuleAddtoFinPriceList.AddtoFinPriceList
    End If
Else
    MsgBox "Product found would you like to add a transaction?", vbYesNo
    If Response = vbNo Then
        MsgBox "Cancelled"
        Unload FinProdIn
    Else
        Call ModuleAddTrans.AddTrans
    End If
End If
End Sub
4

1 回答 1

1

索引匹配工作表函数与评估VBA 方法结合使用。例如,如果您的产品代码(或部件号或其他标识符)在 A2:A5000 范围内,并且在 B2:B5000 和 C2:C5000 中有两个要匹配的条件,则可以使用:

Sub FindVal()
    Const DQTE = """"

    Dim criteria1 As String
    Dim criteria2 As String
    Dim evalStr As String
    Dim prodCode As Variant

    criteria1 = "ABC"
    criteria2 = "DEF"
    evalStr = "INDEX($C$2:$C$5000,MATCH(" & DQTE & criteria1 & DQTE & "&" & DQTE & criteria2 & DQTE & ",$A$2:$A$5000&$B$2:$B$5000,0))"

    prodCode = Evaluate(evalStr)

    If VarType(prodCode) = vbError Then
        MsgBox "No match found"
    Else
        MsgBox "Value found: " & prodCode
    End If
End Sub
于 2013-03-18T17:42:13.283 回答