Forum Discussion
AminuF
Jan 10, 2021Copper Contributor
Vba
I have a vba file I am developing for sales transaction. If I run the vba file and I add a product, I get a run-time error 1004, that unable to get the vlookup property of the worksheetfunction class...
JMB17
Jan 10, 2021Bronze Contributor
If you click on reply, instead of quick reply, you should see where you can attach a file - assuming there is no sensitive information. Otherwise, maybe copy/paste the applicable code. An incorrect argument being passed to the vlookup function may be the problem.
AminuF
Jan 10, 2021Copper Contributor
- JMB17Jan 10, 2021Bronze ContributorThe vlookup functions appear to be working okay for me. Is there a particular procedure and line that is problematic, or are there circumstances (userform inputs) where it's not working?
You could also be getting that error if the value being looked up doesn't exist in the table.- AminuFJan 10, 2021Copper Contributor
- JMB17Jan 10, 2021Bronze ContributorI see. Your Add button (CommandButton6) is clearing the product and type comboboxes. When you clear those comboboxes, it triggers their respective change event handlers (cmb_Product_Change and cmb_Type_Change). Since the combobox values have been cleared, the vlookup formulas within those change event handlers fail.
You could add an IF statement to those event handlers to test the product combobox before attempting the vlookup.
Or, you could add a boolean module level variable to enable/disable events and add an if statement to your event handlers to check that variable and, if false, exit. That way, your code can set that variable to false when it's about to do something that will trigger another event handler that you don't want to run.