0
votes

I have a userform that has comboboxes that lookup a value in a table to populate a textbox on the same userform. The code is working. It produces the desired results and the form data saves accurately to the table, however instead of getting my MsgBox "Saved", I get error 1004 'Unable to get the VLookup property of the worksheet function class.' When I debug the line highlighted is Me.men10.Value = Application.WorksheetFunction.VLookup(rec1, rRange, 47, 0)

This is the sub procedure in it's entirety:

Private Sub men8_Change()
Dim rec1 As String
Dim rRange As Range
Set rRange = Sheets("Recipe Box").Range("tblRecipes")

rec1 = Me.men8.Value
Me.men10.Value = Application.WorksheetFunction.VLookup(rec1, rRange, 47, 0)

End Sub

I have four of these on the form and as I said, everything works as it should but still results in the error. Any suggestions? I have searched everywhere but can't find anything related to errors on working code.

Here is a snippet of the form controls: The circled textbox (men10) is populated from the combobox (men8) above it.

1
does the value exist in the table, are there 47 columns? You don't get #N/A's etc from this. - Nathan_Sav

1 Answers

0
votes

I was able to replicate this, the error occurs if: -

  • It does not find a match. In my scenario it was not concerned about upper or lower case but sure enough if there was no match I get the error you are getting. Do a manual check to ensure you are getting an exact match in the first column of the named range.
  • If I specified column number greater than the number of columns in the named range. Remembering, a value of 1 does not strictly mean column A on the worksheet, but represent the first column in the named range (i.e. If the range is "C5:L200", then a value of 1 in Arg3 (col_index_num) would represent column C in the worksheet.