我在 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