VLookup Worksheet Function: Run TIme 1004 issue

chipsworld

Board Regular
Joined
May 23, 2019
Messages
164
Office Version
  1. 365
I am receiving a "Run Time Error 1004 - Unable to get the VLookup property if the WorksheetFunction" for the below, but not until the 3rd Vlookup runs. Values are in the lookup table, etc...Help! I don't understand why the first two run but not the third and fourth.

The only difference between the values is the first two are all text values and the second two are/can be alpha-numeric...

What am I missing?

VBA Code:
Dim qcntry As String
Dim ccntry As String
Dim qusc As String
Dim cusc As String
Dim wslkup As Worksheet

Set wslkup = Sheets("formulas")

qcntry = Application.WorksheetFunction.VLookup(Me.cmbqcntry.Value, wslkup.Range("AB3:AC25"), 2, False)
ccntry = Application.WorksheetFunction.VLookup(Me.cmbccntry.Value, wslkup.Range("AB3:AC25"), 2, False)
qusc = Application.WorksheetFunction.VLookup(Me.cmbqusc.Value, wslkup.Range("AB3:AC25"), 2, False)
cusc = Application.WorksheetFunction.VLookup(Me.cmbcusc.Value, wslkup.Range("AB3:AC25"), 2, False)[/B]
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Probably no valid match in the range, if the vlookup would return a #N/A error when used as a formula in a worksheet then it will return rte 1004 in vba.
 
Upvote 0
Jason,
I thought the same thing but...nope! The result is there. This is a lookup for status. I set the return value from a pre-determined list and a selection from a combo box.
This just makes no sense to me...was hoping there was some code thing I missed or limitation or ???
 
Upvote 0
I would agree with Jason, it cannot find the cmbqusc value in AB3:AB25.
Check that they are exactly the same, with no leading/trailing spaces.
 
Upvote 0
OK...the value that is causing the issue is a numeric one. If I place an additional alpha character at the end of it in the drop down and the lookup range, it works fine, but as soon as I remove the alpha character, it fails.

Is there some crazy rule for numeric values in vlookups that I am unaware of? I have never seen anything like this before.

Another idea...could I use the worksheet range of values I am looking up in, as the source of the combo box? That would eliminate any possible chance of a miss-match since the source would be the same for both.
 
Upvote 0
Combobox values are text not numerical, which is why you get the problem.
You could load the combos like
VBA Code:
Me.cmbqcntry.List = wslkup.Range("AB3:A25").Value
but you would then have the same values in each combo.
 
Upvote 0
Solution
Fluff,
Found a solution...if I format the entire lookup range on the worksheet as "Text" the VLOOKUP works perfectly.
Thank you for the heads-up on that...was really pulling my hair out.
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,246
Members
452,623
Latest member
cliftonhandyman

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