VBA Vlookup function help please

pete393

New Member
Joined
Jan 23, 2005
Messages
21
Hello every body in my VBA code i have the folowing
xxxlist:
Name = InputBox("enter movie name")
If Name = Cancel Then
noanwser = MsgBox(" YOU DID NOT ENTER A MOVIE NAME DO YOU WISH TO EXIT THE PROGRAM", vbRetryCancel)
If noanwser = vbRetry Then GoTo xxxlist
If noanwser = vbCancel Then GoTo aend

moviedata = Application.WorksheetFunction. _
VLookup(Name, Range("movielistxxx"), 2, False)

now the problem im having is if the vlookup dosent find a corect anwser i get a run time error 1004 how could i make it now show this and even beter if i get this to execute an other function like a msgbox


can you please help this would be great
 

Some videos you may like

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result

pete393

New Member
Joined
Jan 23, 2005
Messages
21
Oh i forgot please dont think rong in my code its says XXX this is were the list name goes and not what you may think...


thanks
 

pete393

New Member
Joined
Jan 23, 2005
Messages
21
Oh i forgot please dont think rong in my code its says XXX this is were the list name goes and not what you may think...


thanks
 

vconfused

Well-known Member
Joined
Jun 11, 2004
Messages
547
Several ways. One is to add error handling:

Code:
Sub macro()
Dim Name As String, moviedata As Variant, noanswer As Variant

Name = InputBox("enter movie name")

    On Error Resume Next
    moviedata = Application.WorksheetFunction.VLookup(Name, Range("movielistxxx"), 2, False)
    If Err.Number <> 0 Then
        Err.Clear
        On Error GoTo 0
        MsgBox "Sorry, match not found"
    Else
        On Error GoTo 0
        MsgBox moviedata
    End If

End Sub
 

vconfused

Well-known Member
Joined
Jun 11, 2004
Messages
547
Another way is to use countif first:

Code:
Sub macro()
Dim Name As String, moviedata As Variant

Name = InputBox("enter movie name")

    If Application.WorksheetFunction.CountIf(Range("movielistxxx"), Name) = 0 Then
        MsgBox "Sorry, match not found"
    Else
        moviedata = Application.WorksheetFunction.VLookup(Name, Range("movielistxxx"), 2, False)
        MsgBox moviedata
    End If

End Sub
 

pete393

New Member
Joined
Jan 23, 2005
Messages
21
Thank you

Hello again just whanted to say thank alot this works great

you guys are great


:biggrin: :biggrin:
:pray: :pray:
 

Watch MrExcel Video

Forum statistics

Threads
1,122,514
Messages
5,596,611
Members
414,080
Latest member
penguin23

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
Top