Use vlookup in VBA

Shadkng

Active Member
Joined
Oct 11, 2018
Messages
365
Hi, I would like to use the vlookup/if statement below to call a macro. If the "Y" is absent, then I dont want the macro to run. If someone could provide the correct format I would appreciate it. It is written in the code below. Thanks

IF(VLOOKUP(FINALORDER!D4,DEALERLIST!$A$3:$O$20,15,FALSE)="Y" Then
Call QUOTE_INVOICE_PDF
End If



VBA Code:
Sub PRINT_ADAM_4_FORMS()
'Revision - Added INVOICE copies condition
'           11/04/2019 - Chris at Lum Computer Services lumcs50@yahoo.com
'
response = MsgBox("THIS WILL PRINT YOUR FORMS - ARE YOU SURE?", vbYesNo)
    If response = vbNo Then
        Exit Sub
    End If
Application.Dialogs(xlDialogPrinterSetup).Show
Application.ScreenUpdating = False
Call PARTS_LIST_PRINT  'STEVE ADDED 11/14/21  12/1/21 MOVED THIS LINE SO PARTS LIST PRINTS FIRST PER ADAM REQUEST
Worksheets("MASTER FORM").PrintOut Copies:=2
Worksheets("PACK SLIP").PrintOut


If Worksheets("FINALORDER").Range("F5").Value = "BA" Then
    Worksheets("INVOICE").PrintOut Copies:=3
Else
    Worksheets("INVOICE").PrintOut Copies:=1  'this will print 1 full copy of the invoice which goes to customer
    Worksheets("INVOICE").PrintOut from:=1, To:=1, Copies:=1 '1/27/20 Steve added this to print just tghe first page of the 2nd copy of invoice which stays with us.

End If

[SIZE=4]IF(VLOOKUP(FINALORDER!D4,DEALERLIST!$A$3:$O$20,15,FALSE)="Y" Then
Call QUOTE_INVOICE_PDF
End If[/SIZE]

ActiveSheet.Select
Application.ScreenUpdating = True
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
VBA Code:
If Evaluate("=VLOOKUP(FINALORDER!D4,DEALERLIST!$A$3:$O$20,15,FALSE)") = "Y" Then
    Call QUOTE_INVOICE_PDF
End If
 
Upvote 0
Solution
To cover off a not found scenario, you might want to put @Phuoc's code between either of these 2 options:
VBA Code:
On Error Resume Next
'....
On Error Goto 0

' OR
If Not IsError(Evaluate("=VLOOKUP(FINALORDER!D4,DEALERLIST!$A$3:$O$20,15,FALSE)")) then
'...
End if
 
Upvote 0

Forum statistics

Threads
1,215,063
Messages
6,122,935
Members
449,094
Latest member
teemeren

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