VBA VLOOKUP error - expected list separator or )

mcchase

New Member
Joined
Oct 16, 2023
Messages
10
Office Version
  1. 365
Platform
  1. Windows
I am getting this error for the vlookup below, where ":" is highlighted. How do I fix this? Thanks

x = VLookup(valvekey, model_table!A1:C3500, 2, False)
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Welcome to the Board!

VLOOKUP is a worksheet function, not a VBA one. So you cannot use it in VBA like that.
This link shows you how you can use it in VBA: Vlookup in Excel VBA
 
Upvote 0
Welcome to the Board!

VLOOKUP is a worksheet function, not a VBA one. So you cannot use it in VBA like that.
This link shows you how you can use it in VBA: Vlookup in Excel VBA
I didn't know that. Right now I have data on multiple sheets, say sheets A,B,C. The user hits a button on the main sheet, which triggers VBA to go thru sheets A,B,C to find a match in the 1st column of those sheets with data in the price sheet. This is proving to be time-consuming, as there could be 20-30 values in each sheet (A,B,C) which must be found in the price sheet. I thought vlookup would be quicker than executing an IF loop multiple times.
 
Upvote 0
I didn't know that. Right now I have data on multiple sheets, say sheets A,B,C. The user hits a button on the main sheet, which triggers VBA to go thru sheets A,B,C to find a match in the 1st column of those sheets with data in the price sheet. This is proving to be time-consuming, as there could be 20-30 values in each sheet (A,B,C) which must be found in the price sheet. I thought vlookup would be quicker than executing an IF loop multiple times.
Note that I am NOT saying you cannot use VLOOKUP in VBA. I am just saying your syntax for using it is not correct, as it the function does not natively exist in VBA.
But you can call many worksheet functions in VBA by prefacing it with "WorksheetFunction".
So you just have to change your syntax to reference it correctly.

Take a look at that link in detail. It shows you how to do that.
 
Upvote 0
I looked at the link and another one. I added WORKSHEETfUNCTION and RANGE, and debug says it's ok, but now I'm getting Rin-time error '424'. I looked-up the message but don't see what's wrong. Can you help with this?

xx = WorksheetFunction.VLookup(valvekey, model_table.Range("A1:C3500"), 2, False)
 
Upvote 0
Is "model_table" the name of a sheet or a table?
 
Upvote 0
OK, assuming the "valvekey" is a valid variable in VBA with a value, then try something like this:
VBA Code:
Dim rng as Range
Set rng=Sheets("model_table").Range("A1:C3500")
xx = WorksheetFunction.VLookup(valvekey, rng, 2, False)
 
Upvote 0
now I'm getting "unable to get the property of the worksheetfunction class". Looking around could it be that valvekey is Variant/String and column A in model_table is General??? I did add a row in model_table containing "A" and tried the vlookup where valvekey = "A" and still got same error...I thought the error was because it couldn't find the original valvekey.
 
Upvote 0
From VBA, if you go to the Tools menu and select References, which entries to you see selected?
Do you see these four?

1697483219727.png


Also, what is the name of the module that you have placed the VBA code in?
Have you placed it in a new, general module, or in a Sheet module?
Please put in in a General module.
 
Upvote 0

Forum statistics

Threads
1,215,510
Messages
6,125,228
Members
449,216
Latest member
biglake87

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top