Function ProtectiveDiscount(PDD As Range)
'‘Find discount in table
TotalDiscount = 0
For i = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(i).Value = "Dead bolt, Local Fire Alarm, Fire extinguisher" Then
Msg = Msg & ListBox1.List(i) & vbNewLine
TotalDiscount = TotalDiscount + WorksheetFunction.VLookup(ListBox1.Selected(i).Value, Worksheets("Sheet4").Range("PDD"), 2, False)
' TotalDiscount = TotalDiscount + WorksheetFunction.VLookup(ListBox1.Selected(i).Value, Range("R50:S55"), 2, False)
End If
If ListBox1.Selected(i).Value = "Burglar Alarm with Reporting" Then
Msg = Msg & ListBox1.List(i) & vbNewLine
TotalDiscount = TotalDiscount + WorksheetFunction.VLookup(ListBox1.Selected(i).Value, PDD, 2, False)
' TotalDiscount = TotalDiscount + WorksheetFunction.VLookup(ListBox1.Selected(i).Value, Range("R50:S55"), 2, False)
End If
If ListBox1.Selected(i).Value = "Fire Alarm with Reporting" Then
Msg = Msg & ListBox1.List(i) & vbNewLine
TotalDiscount = TotalDiscount + WorksheetFunction.VLookup(ListBox1.Selected(i).Value, Worksheets("Sheet4").Range("PDD"), 2, False)
'TotalDiscount = TotalDiscount + WorksheetFunction.VLookup(ListBox1.Selected(i).Value, Range("R50:S55"), 2, False)
End If
If ListBox1.Selected(i).Value = "Automatic Sprinkler in all areas" Then
Msg = Msg & ListBox1.List(i) & vbNewLine
TotalDiscount = TotalDiscount + WorksheetFunction.VLookup(ListBox1.Selected(i).Value, Worksheets("Sheet4").Range("PDD"), 2, False)
' TotalDiscount = TotalDiscount + WorksheetFunction.VLookup(ListBox1.Selected(i).Value, Range("R50:S55"), 2, False)
End If
End Function
由於某種原因,我的查找功能不起作用。我嘗試了幾種方法,並且陷入困境。任何人都可以提供任何幫助Excel 2010 VBA查找功能問題
我看到'for',而不是'next'?這是一個錯字,還是你真的面臨一些錯誤? – Passerby
接下來我只是無法適應所有的代碼。我沒有得到一個錯誤,但我得到#Value在單元格中返回 – user1667541
你沒有從你的函數返回任何值。某處應該有一行'ProtectiveDiscount = [whateverValueYouCalculated]'你有第二次查找使用該函數的PDD參數而其他人不這樣做的原因嗎? –