VLookup VBA

Wardylewis

New Member
Joined
Jun 7, 2016
Messages
37
Good evening,

I attempting to use a Vlookup as to provide me with a yes-no answer and then use that to lock out a box if the answer is "No".

I need to define the sheet as it will be hidden to the user as they input data on a Userform.

However, every time I run this code I get a run-time error '1004': Unable to get the Vlookup property of the WorksheetFunction Class.

I've googled everything but cannot seem to fix it, can anybody assist please?

Code:
Audio = Application.WorksheetFunction.VLookup(TextBox1.Value, Worksheets("Employee List").Range("A:P"), 12, 0)

If Audio = "No" Then
ComboBox1.Enabled = False
TextBox5.Enabled = False
End If
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
The range specified in your Vlookup is too large.
Limit the Vlookup by finding first the last row.

Use the following code:
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]
Code:
LastRow = Sheets("Employee List").Range("A1").SpecialCells(xlCellTypeLastCell).Row
Audio = Application.WorksheetFunction.VLookup(ActiveSheet.Shapes("TextBox 1").OLEFormat.Object.Text, Sheets("Employee List").Range("A1:P" & LastRow), 12, 0)
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]If Audio = "No" Then
ComboBox1.Enabled = False
TextBox5.Enabled = False
End If[/FONT]

Regards
[/FONT]
 
Upvote 0
Try this to set the Audio variable:

Code:
Audio = Evaluate("VLOOKUP(""" & Me.TextBox1.Value & """,'Employee List'!A:P,12,FALSE)")

Regards,

Robert
 
Upvote 0
Good Morning @Rino702 and @Trebor76.

I have tried both of these but none are working I either get a mismatch error or Unable to get the Vlookup property of the WorksheetFunction Class

Have you got any idea why?
 
Last edited:
Upvote 0
What type of values do you have in column A on the 'Employee List' sheet?
 
Upvote 0
My bad - I assumed the data was text. Se if this resolves the issue:

Code:
Audio = Evaluate("VLOOKUP(" & Me.TextBox1.Value & ",'Employee List'!A:P,12,FALSE)")

Robert
 
Upvote 0
How about
Code:
Dim Audio As Variant
Audio = Application.vlookup(Val(TextBox1.Value), Worksheets("Employee List").Range("A:P"), 12, 0)
If IsError(Audio) Then
   MsgBox "ID not found"
ElseIf Audio = "no" Then
   ComboBox1.Enabled = False
   TextBox5.Enabled = False
End If
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,814
Messages
6,181,127
Members
453,021
Latest member
Justyna P

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