A
Abhinandan
Hi I am new to VBA Programming. So excuse me if the question is a very basic
one.
I am trying to write a macro for to calculate price and stock availability
for a product . Before I look for the product by typing the product number, I
want to test whether the product number is within the defined range. Only
when the product is within the defined range, only then I want to use a
Vlookup finction to calculate the price and stock. If the Product is not
within the range then i want to just get a messgae as product code is not in
the range.
Below is the macro which i wrote. I use Office 2007
Sub test_vlo()
Dim product As String
Dim price As Double
Dim stock As Integer
product = InputBox("Enter the Product Code")
If TypeName(product) = Application.Worksheets(1).Range("a1:j33822").Text
Then
price = Application.WorksheetFunction.vlookup(product, _
Range("a1:j33822"), 5, False)
stock = Application.WorksheetFunction.vlookup(product, _
Range("a1:j33822"), 6, False)
MsgBox product & " price is " & price & " stock is " & stock
Else
MsgBox Application.UserName & " The Product Code does not Exist"
End If
However the problem with this code is that even for the product number
within the defined range, it comes up with an erroe message as The Product
code does not exist.
Can some point me in the right direction
one.
I am trying to write a macro for to calculate price and stock availability
for a product . Before I look for the product by typing the product number, I
want to test whether the product number is within the defined range. Only
when the product is within the defined range, only then I want to use a
Vlookup finction to calculate the price and stock. If the Product is not
within the range then i want to just get a messgae as product code is not in
the range.
Below is the macro which i wrote. I use Office 2007
Sub test_vlo()
Dim product As String
Dim price As Double
Dim stock As Integer
product = InputBox("Enter the Product Code")
If TypeName(product) = Application.Worksheets(1).Range("a1:j33822").Text
Then
price = Application.WorksheetFunction.vlookup(product, _
Range("a1:j33822"), 5, False)
stock = Application.WorksheetFunction.vlookup(product, _
Range("a1:j33822"), 6, False)
MsgBox product & " price is " & price & " stock is " & stock
Else
MsgBox Application.UserName & " The Product Code does not Exist"
End If
However the problem with this code is that even for the product number
within the defined range, it comes up with an erroe message as The Product
code does not exist.
Can some point me in the right direction