Reputation: 3
I have an error on the vlookup, the error says 'Unable to get vlookup property of the worksheetfunction class'
this is my code:
Private Sub Yes_Click()
Dim input_value As Variant
Dim rg As Range
Set rg = Sheet2.Range("B8:C17")
msg = InputBox("What is your name?")
If msg = WorksheetFunction.VLookup(msg, rg, 2) Then
Yes.Value = True
Else
MsgBox ("Name already in database.")
Yes.Value = False
End If
End Sub
There is no error if the name i keyed in is already in the database. however, there is an error when the name
Upvotes: 0
Views: 108
Reputation: 199
Don’t use that function. I’m VBA there’s a method ‘Find’ for that
Dim findmsg as Range
Dim rg As Range
Set rg = Sheets("Sheet2").Range("B8:C17")
msg = InputBox(“What is your name?”)
Set findmsg = rg.find(msg)
If not findmsg is nothing then 'This condition means the names is on the database
MsgBox(“Name already exists in database”)
Yes.value=false
Else
Yes.value = true
End if
Upvotes: 1