Vba

%3CLINGO-SUB%20id%3D%22lingo-sub-2046089%22%20slang%3D%22en-US%22%3EVba%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2046089%22%20slang%3D%22en-US%22%3E%3CP%3EI%20have%20a%20vba%20file%20I%20am%20developing%20for%20sales%20transaction.%20If%20I%20run%20the%20vba%20file%20and%20I%20add%20a%20product%2C%20I%20get%20a%20run-time%20error%201004%2C%20that%20unable%20to%20get%20the%20vlookup%20property%20of%20the%20worksheetfunction%20class.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2046089%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EMacros%20and%20VBA%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2046120%22%20slang%3D%22en-US%22%3ERE%3A%20Vba%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2046120%22%20slang%3D%22en-US%22%3EIt's%20hard%20to%20say%20without%20seeing%20the%20vba%20code.%20As%20a%20shot%20in%20the%20dark%2C%20are%20you%20referencing%20the%20lookup%20range%20as%20%22A1%3AB10%22%2C%20for%20example%3A%20application.WorksheetFunction.VLookup(%22x%22%2C%22A1%3AB10%22%2C2%2C0)%20which%20is%20one%20way%20it%20will%20fail%20with%20the%20error%20you%20are%20seeing)%2C%20or%20are%20you%20using%20a%20range%20object%2C%20such%20as%20Range(%22A1%3AB10%22)%2C%20like%3A%20application.WorksheetFunction.VLookup(%22x%22%2Crange(%22A1%3AB10%22)%2C2%2C0)%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2046126%22%20slang%3D%22en-US%22%3ERE%3A%20Vba%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2046126%22%20slang%3D%22en-US%22%3EIf%20you%20click%20on%20reply%2C%20instead%20of%20quick%20reply%2C%20you%20should%20see%20where%20you%20can%20attach%20a%20file%20-%20assuming%20there%20is%20no%20sensitive%20information.%20Otherwise%2C%20maybe%20copy%2Fpaste%20the%20applicable%20code.%20An%20incorrect%20argument%20being%20passed%20to%20the%20vlookup%20function%20may%20be%20the%20problem.%3C%2FLINGO-BODY%3E
New Contributor

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.

7 Replies
It's hard to say without seeing the vba code. As a shot in the dark, are you referencing the lookup range as "A1:B10", for example: application.WorksheetFunction.VLookup("x","A1:B10",2,0) which is one way it will fail with the error you are seeing), or are you using a range object, such as Range("A1:B10"), like: application.WorksheetFunction.VLookup("x",range("A1:B10"),2,0)
how do I send the file?
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.

@JMB17 

The 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.

@JMB17 

I 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.