Home » excel » excel vba – Multiple vlookup statements when assigning value to userform box

excel vba – Multiple vlookup statements when assigning value to userform box

Posted by: admin May 14, 2020 Leave a comment

Questions:

Good Morning,

I’ve created a userform where users can look up the name of a person, and it returns (among other things) their address. The statement used for the address lookup went like this:

.Address = Application.WorksheetFunction.VLookup(Me.Name1, _
Worksheets("Caselist").Range("Lookup"), 10, 0)

This worked fine. Since then, I’ve split the Address cell into 3 separate cells (Street, City, Zip). I’d like to combine the values in all 3 cells before I add them to the Userform, so users can see the complete address. I’ve tried a statement like this:

.Address = Application.WorksheetFunction.VLookup(Me.Name1,Worksheets("Caselist") _ 
.Range("Lookup"), 10, 0) & _ 
Application.WorksheetFunction.VLookup(Me.Name1,Worksheets("Caselist") _ 
.Range("Lookup"), 11, 0) & " MI, " & _
Application.WorksheetFunction.VLookup(Me.Name1,Worksheets("Caselist") _
.Range("Lookup"), 12, 0)

I know that’s hard to look at, but it essentially is 3 Vlookup statements connected together using “&” to create one string. When I attempt this, I get the following error

“Unable to get the VLookup property of the WorksheetFunction class”

I haven’t found any way to format this successfully online. Any ideas how to do this?

How to&Answers:

I’m 90% sure your named range Lookup doesn’t extend to columns 11 and 12. Attempting to use Application.WorksheetFunction.Vlookup and asking for a return column outside the range will return a

Run-time error ‘1004’ – Unable to get the VLookup property of the WorksheetFunction class.

This is one of the plights of using named ranges in code – it’s not something you can clearly see while debugging, and the error you receive is rather ambiguous :).