Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么不是';这玩意儿不管用吗?VBA_Vba_Excel - Fatal编程技术网

为什么不是';这玩意儿不管用吗?VBA

为什么不是';这玩意儿不管用吗?VBA,vba,excel,Vba,Excel,我试图做的是能够双击列表框中的型号,然后使用Hlookup在单独位置的实际列表中查找值。最终一个简单的计算将被执行,但我被困在这个小家伙 只是为了获得一些附加信息,Pricelist是a为包含model的表指定的名称,price和ListModel是列表框的名称 Private Sub ListModel_DblClick(ByVal Cancel As MSForms.ReturnBoolean) Dim perDiscountRate As Double Dim PerDiscountPr

我试图做的是能够双击列表框中的型号,然后使用Hlookup在单独位置的实际列表中查找值。最终一个简单的计算将被执行,但我被困在这个小家伙

只是为了获得一些附加信息,Pricelist是a为包含model的表指定的名称,price和ListModel是列表框的名称

Private Sub ListModel_DblClick(ByVal Cancel As MSForms.ReturnBoolean)

Dim perDiscountRate As Double
Dim PerDiscountPrice As Currency
Dim PriceList As String

perDiscountRate = InputBox("What is the discount rate", "Discount Calculator", "10") / 100
Application.Workbooks("T6-EX-E1D.xlsm").Worksheets("Computers").Range("c6:c8").Value = perDiscountRate

perDiscountRate = Application.WorksheetFunction.VLookup("ListModel.Selected",   PriceList, 2)

End Sub

如果我猜对了你的目标,你会用

Dim sht As Worksheet

Set sht = Application.Workbooks("T6-EX-E1D.xlsm").Worksheets("Computers")
With Me.ListModel
    PerDiscountPrice = Application.WorksheetFunction.VLookup(.List(.ListIndex), sht.Range("PriceList"), 2, 0)
End With
我认为“价格表”是“T6-EX-E1D.xlsm”工作簿“计算机”工作表中的“指定范围”


如果没有,请根据您的需要更改参考资料

谢谢您的帮助。我能够让代码正常工作。这是它的样子

Private Sub ListModel_DblClick(ByVal Cancel As MSForms.ReturnBoolean)

Dim perDiscountRate As Double
Dim PerDiscountPrice As Currency
Dim PriceList As Range
Dim Org As Worksheet

Set Org = Application.Workbooks("T6-EX-E1D.xlsm").Worksheets("Computers")


perDiscountRate = InputBox("What is the discount rate", "Discount Calculator", "10") / 100
Application.Workbooks("T6-EX- E1D.xlsm").Worksheets("Computers").Range("c6:c8").Value = perDiscountRate
PerDiscountPrice = Application.WorksheetFunction.VLookup(ListModel,  Range("PriceList"), 2)

Application.Workbooks("T6-EX-E1D.xlsm").Worksheets("Computers").Range("d6:d8").Value = PerDiscountPrice



End Sub
我把ListModel.selected放在Vlookup中,使第一个参数过于复杂。仅仅使用ListModel这个名称就足够了

最好的,
扎克

HLOOKUP
VLOOKUP
?您的标题中有一个,代码中有一个。什么是
“ListModel.Selected”
?您没有正确查找。此链接可能会帮助您摆脱困境:[我的错,这是一个Vlookup。您将PriceList作为字符串,但它需要是一个范围。您需要将范围传递给Vlookup的第二个参数