Hi
i am currently learning VBA, and something that i thought should be easy to execute is proving to be a pain.....
Sub TestVlookup()
Dim Product As Variant
Dim Price As Double
Product = InputBox("What code are you looking for?")
Worksheets("Database").Activate
Price = WorksheetFunction.VLookup(Product, Range("Price"), 2, False)
MsgBox ("The cost of the product" & Product & " is" & Price)
Database sheet:
[TABLE="width: 128"]
<colgroup><col width="64" span="2" style="width:48pt"> </colgroup><tbody>[TR]
[TD="width: 64"]Product[/TD]
[TD="width: 64"]Price[/TD]
[/TR]
[TR]
[TD="align: right"]23[/TD]
[TD="align: right"]1.99[/TD]
[/TR]
[TR]
[TD="align: right"]24[/TD]
[TD="align: right"]25.64[/TD]
[/TR]
[TR]
[TD="align: right"]25[/TD]
[TD="align: right"]13.98[/TD]
[/TR]
[TR]
[TD="align: right"]26[/TD]
[TD="align: right"]11[/TD]
[/TR]
[TR]
[TD="align: right"]27[/TD]
[TD="align: right"]14.79
[/TD]
[/TR]
</tbody>[/TABLE]
I keep getting a 1004 error......Which is being caused by the vlookup- i have defined the variables and labeles the data sources (name range) as accordingly, but unable to figure out what is going on?
i am currently learning VBA, and something that i thought should be easy to execute is proving to be a pain.....
Sub TestVlookup()
Dim Product As Variant
Dim Price As Double
Product = InputBox("What code are you looking for?")
Worksheets("Database").Activate
Price = WorksheetFunction.VLookup(Product, Range("Price"), 2, False)
MsgBox ("The cost of the product" & Product & " is" & Price)
Database sheet:
[TABLE="width: 128"]
<colgroup><col width="64" span="2" style="width:48pt"> </colgroup><tbody>[TR]
[TD="width: 64"]Product[/TD]
[TD="width: 64"]Price[/TD]
[/TR]
[TR]
[TD="align: right"]23[/TD]
[TD="align: right"]1.99[/TD]
[/TR]
[TR]
[TD="align: right"]24[/TD]
[TD="align: right"]25.64[/TD]
[/TR]
[TR]
[TD="align: right"]25[/TD]
[TD="align: right"]13.98[/TD]
[/TR]
[TR]
[TD="align: right"]26[/TD]
[TD="align: right"]11[/TD]
[/TR]
[TR]
[TD="align: right"]27[/TD]
[TD="align: right"]14.79
[/TD]
[/TR]
</tbody>[/TABLE]
I keep getting a 1004 error......Which is being caused by the vlookup- i have defined the variables and labeles the data sources (name range) as accordingly, but unable to figure out what is going on?