If(And) with a Vlookup

0267Kim

New Member
Joined
Aug 20, 2019
Messages
13
Hi everyone,

I have a situation where I've got a spreadsheet with 2 different columns of data that must match. If they match, I'll need to do a vlookup in order to find a specific account ID on another sheet.



What I want to do is from sheet 1, if Acct Type = "Deposit", and Tender Type = "Cash", then I want the function to do a Vlookup based on the store and sheet 2 . So for store 10001, the vlookup would look at column 2 and return deposit acct D1234, otherwise have another nested if statement.

I was thinking =IF(AND(Acct Type = "Deposit", Tender Type = "Cash"),vlookup(Sheet1!A3,Sheet2!E:G,2,FALSE),IF(AND(Acct Type = "Disbursement", Tender Type = "Check"...etc...

I keep getting an #N/A. Any help with the syntax would be greatly appreciated.

Thank you.
 
Last edited by a moderator:

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Re: Help with an If(And) with a Vlookup

#N/A means the VLOOKUP failed

It should be something along the lines of

IFERRO(VLOOKUP...IFERROR(VLOOKUP...))

You need to explain this fully

=IF(AND(Acct Type = "Deposit", Tender Type = "Cash"),vlookup(Sheet1!A3,Sheet2!E:G,2,FALSE),IF(AND(Acct Type = "Disbursement", Tender Type = "Check"...etc...

What happens if Disbursement and Check... ?

Are there other Account and tender Types you need to check for?
Are you searching the same range as Deposit and Cash or some other range?
 
Last edited:
Upvote 0
Re: Help with an If(And) with a Vlookup

I was able to get this working. A Sample of the formula is below:

=IF(AND(R2="Cash",Q2="Payment"),VLOOKUP(G2,'TMX Store Report'!K:AE,12,0)

What I'm tying to do is say, If this and that, then vlookup store number in column 12 of other report. So, the criteria are Tender Type (here "Cash") and Transaction Type (here "Payment") and store. There are many possible combinations of Tender Type and Transaction Type and thousands of stores. Each combination will tell the Vlookup to go look at a specific column on the store report (here, column 12).

Here's a few more of the many combinations:
YXD2iPmvyD3fkutlFm2BxEP0fdZ5tGAlssrUAAAAASUVORK5CYII=




The issue I'm having now is with so many combinations of Tender and Transaction type and store, I've run into an error which says "This formula can't be entered because it uses more than 64 levels of nesting." Is there a way around this? I thought about combining all data points into a table and then using an index match, but literally, there are thousands of possible combinations.
 
Upvote 0
Re: Help with an If(And) with a Vlookup

Sorry, my example data didn't take:

Transaction Type Tender Type Store
Payment ACH 100045
Payment Bank Card 100045
Payment Cash 100045
Payment Money Order 100045
 
Upvote 0
Re: Help with an If(And) with a Vlookup

Yep if you have lots of nested condtions you should be looking at a a table with a straight lookup/INDEX( MATCH())
 
Upvote 0
Re: Help with an If(And) with a Vlookup

I'm having trouble visualizing this.

The way it's currently set up is on Report 1, have the afore mentioned Store, Transaction Type, and Tender Type. One Report 2 I have Store, and Bank Acct1, Bank Acct2, Bank Acct3.

The result I want I the correct Bank Acct from Report 2 based on the Tender Type and Transaction Type from Report 1. With Store ID being on both Report 1 and Report 2.

I'm thinking my Index should be all possible combinations of Store, Trans Type, and Tender Type from Report 1. The Match would have to be where each combination of Store, Trans Type, and Tender Type is unique.

Then I would almost have to Vlookup again to get the proper Bank Acct from Report 2.

What am I missing?
 
Upvote 0
Re: Help with an If(And) with a Vlookup

Urm nope not from your description.

"on Report 1, have the afore mentioned Store, Transaction Type, and Tender Type."
"On Report 2 I have Store, and Bank Acct1, Bank Acct2, Bank Acct3."

So the ONLY thing linking report 1 and report 2 is Store, NOT transaction type or tender type. Transaction and tender type are irrelevant since they dont appear on report 2 or you would have said they appear on both reports. What connects report1 and report 2 is the Store, and Store alone nothing else.

If this is not how your data looks then use the link below to display what the data for report1 and report2 actually look like.

Post a sample spreadsheet with expected results, remove any sensitive data, create a mockup example if necessary.
You cant attach files on this forum. There are tools on this forum for adding small spreadsheet images

https://www.mrexcel.com/forum/about-board/508133-attachments.html
 
Last edited:
Upvote 0
Re: Help with an If(And) with a Vlookup

Sorry for the delayed response. It took me a little while to figure out how to post up a sample. Hopefully this works!


Sheet 1 "Transaction Type and Tender Type"

Book1
ABCD
1Bank AccountStoreTransaction TypeTender Type
2DEB0112222PaymentBank Card
3DA0112222PaymentCash
4DA0112222PaymentCash
5DA0112222PaymentCash
6DEB0112222Pay OffBank Card
7DA0112222SaleCashier's Check
8DA0112222PaymentCash
9DEB0112222PaymentBank Card
10DEB0112222PaymentBank Card
Cash Sheet
Cell Formulas
RangeFormula
A2=IF(AND(D2="Cash",C2="Payment"),VLOOKUP(B2,'Store Report'!A:J,2,0),IF(AND(D2="Cashier's Check",C2="Payment"),VLOOKUP(B2,'Store Report'!A:J,2,0),IF(AND(D2="Money Order",C2="Payment"),VLOOKUP(B2,'Store Report'!A:J,2,0),IF(AND(D2="Bank Card",C2="Payment"),VLOOKUP(B2,'Store Report'!A:J,4,0),IF(AND(D2="Card (Auto)",C2="Payment"),VLOOKUP(B2,'Store Report'!A:J,5,0),IF(AND(D2="Posted Collections",C2="Payment"),VLOOKUP(B2,'Store Report'!A:J,6,0),IF(AND(D2="Western Union",C2="Payment"),VLOOKUP(B2,'Store Report'!A:J,8,0),IF(AND(D2="ACH",C2="Payment"),VLOOKUP(B2,'Store Report'!A:J,3,0),IF(AND(D2="Trustee Payment",C2="Payment"),VLOOKUP(B2,'Store Report'!A:J,7,0),IF(AND(D2="Bank Card",C2="Payment - Void"),VLOOKUP(B2,'Store Report'!A:J,4,0),IF(AND(D2="Card (Auto)",C2="Payment - Void"),VLOOKUP(B2,'Store Report'!A:J,5,0),IF(AND(D2="Cash",C2="Payment - Void"),VLOOKUP(B2,'Store Report'!A:J,2,0),IF(AND(D2="Cashier's Check",C2="Payment - Void"),VLOOKUP(B2,'Store Report'!A:J,2,0),IF(AND(D2="Money Order",C2="Payment - Void"),VLOOKUP(B2,'Store Report'!A:J,2,0),IF(AND(D2="Card (Auto)",C2="Payment - Void"),VLOOKUP(B2,'Store Report'!A:J,5,0),IF(AND(D2="Posted Collections",C2="Payment - Void"),VLOOKUP(B2,'Store Report'!A:J,6,0),IF(AND(D2="ACH",C2="Payment - Void"),VLOOKUP(B2,'Store Report'!A:J,3,0),IF(AND(D2="Trustee Payment",C2="Payment - Void"),VLOOKUP(B2,'Store Report'!A:J,7,0),IF(AND(D2="ACH",C2="Payment- Returned"),VLOOKUP(B2,'Store Report'!A:J,3,0),IF(AND(D2="Cash",C2="Pay Off"),VLOOKUP(B2,'Store Report'!A:J,2,0),IF(AND(D2="Money Order",C2="Pay Off"),VLOOKUP(B2,'Store Report'!A:J,2,0),IF(AND(D2="Cashier's Check",C2="Pay Off"),VLOOKUP(B2,'Store Report'!A:J,2,0),IF(AND(D2="Money Order",C2="Pay Off"),VLOOKUP(B2,'Store Report'!A:J,2,0),IF(AND(D2="Bank Card",C2="Pay Off"),VLOOKUP(B2,'Store Report'!A:J,4,0),IF(AND(D2="Card (Auto)",C2="Pay Off"),VLOOKUP(B2,'Store Report'!A:J,5,0),IF(AND(D2="Posted Collections",C2="Pay Off"),VLOOKUP(B2,'Store Report'!A:J,6,0),IF(AND(D2="Western Union",C2="Pay Off"),VLOOKUP(B2,'Store Report'!A:J,8,0),IF(AND(D2="Trustee Payment",C2="Pay Off"),VLOOKUP(B2,'Store Report'!A:J,7,0),IF(AND(D2="Bank Card",C2="Pay Off - Void"),VLOOKUP(B2,'Store Report'!A:J,4,0),IF(AND(D2="Cash",C2="Pay Off - Void"),VLOOKUP(B2,'Store Report'!A:J,2,0),IF(AND(D2="Cashier's Check",C2="Pay Off - Void"),VLOOKUP(B2,'Store Report'!A:J,2,0),IF(AND(D2="Money Order",C2="Pay Off - Void"),VLOOKUP(B2,'Store Report'!A:J,2,0),IF(AND(D2="Cash",C2="Rescind"),VLOOKUP(B2,'Store Report'!A:J,2,0),IF(AND(D2="Cashier's Check",C2="Rescind"),VLOOKUP(B2,'Store Report'!A:J,2,0),IF(AND(D2="Bank Card",C2="Rescind"),VLOOKUP(B2,'Store Report'!A:J,4,0),IF(AND(D2="Cashier's Check",C2="Rescind - Void"),VLOOKUP(B2,'Store Report'!A:J,2,0),IF(AND(D2="Cash",C2="NSF Prepayment"),VLOOKUP(B2,'Store Report'!A:J,2,0),IF(AND(D2="Bank Card",C2="NSF Prepayment"),VLOOKUP(B2,'Store Report'!A:J,4,0),IF(AND(D2="Card (Auto)",C2="NSF Prepayment"),VLOOKUP(B2,'Store Report'!A:J,5,0),IF(AND(D2="Cashier's Check",C2="NSF Prepayment"),VLOOKUP(B2,'Store Report'!A:J,2,0),IF(AND(D2="Cash",C2="Sale"),VLOOKUP(B2,'Store Report'!A:J,2,0),IF(AND(D2="Cashier's Check",C2="Sale"),VLOOKUP(B2,'Store Report'!A:J,2,0),IF(AND(D2="Money Order",C2="Sale"),VLOOKUP(B2,'Store Report'!A:J,2,0),IF(AND(D2="Bank Card",C2="Sale"),VLOOKUP(B2,'Store Report'!A:J,4,0),IF(AND(D2="Posted Collections",C2="Sale"),VLOOKUP(B2,'Store Report'!A:J,6,0),IF(AND(D2="Bank Card",C2="Sale - Void"),VLOOKUP(B2,'Store Report'!A:J,4,0),IF(AND(D2="Cashier's Check",C2="Sale - Void"),VLOOKUP(B2,'Store Report'!A:J,2,0),IF(AND(D2="Money Order",C2="Sale - Void"),VLOOKUP(B2,'Store Report'!A:J,2,0),IF(AND(D2="Posted Collections",C2="Sale - Void"),VLOOKUP(B2,'Store Report'!A:J,6,0),IF(AND(D2="Check",C2="Refund"),VLOOKUP(B2,'Store Report'!A:J,2,0),IF(AND(D2="Check",C2="Refund - Void"),VLOOKUP(B2,'Store Report'!A:J,2,0),IF(AND(D2="Check",C2="Advance"),VLOOKUP(B2,'Store Report'!A:J,10,0),IF(AND(D2="Western Union",C2="Advance"),VLOOKUP(B2,'Store Report'!A:J,10,0),IF(AND(D2="Check",C2="Advance - Void"),VLOOKUP(B2,'Store Report'!A:J,10,0),IF(AND(D2="Check",C2="Refinance"),VLOOKUP(B2,'Store Report'!A:J,10,0),IF(AND(D2="Check",C2="Refinance - Void"),VLOOKUP(B2,'Store Report'!A:J,10,0),IF(AND(D2="Check",C2="Refinance/Add-on"),VLOOKUP(B2,'Store Report'!A:J,10,0),IF(AND(D2="Western Union",C2="Refinance/Add-on"),VLOOKUP(B2,'Store Report'!A:J,8,0),IF(AND(D2="Check",C2="Refinance/Add-on - Void"),VLOOKUP(B2,'Store Report'!A:J,10,0),IF(AND(D2="ACH",C2="ACH Payment Clear"),VLOOKUP(B2,'Store Report'!A:J,3,0),IF(AND(D2="ACH",C2="ACH Payment Clear - Void"),VLOOKUP(B2,'Store Report'!A:J,3,0),IF(AND(D2="ACH",C2="ACH Prepayment Applied"),VLOOKUP(B2,'Store Report'!A:J,3,0),IF(AND(D2="ACH",C2="ACH Payment Returned"),VLOOKUP(B2,'Store Report'!A:J,3,0),IF(AND(D2="ACH",C2="ACH Prepayment Returned"),VLOOKUP(B2,'Store Report'!A:J,3,0),"No"))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))


Sheet 2 "Store Report"
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]
Book1
ABCDEFGHIJ
112345678910
2Store CodeDeposit AccountACH (Personal Loan)Debit AccountDebit Card (Auto)Posted CollectionsTrustee AccountWestern Union AccountExpense AccountLoan Account
312222DA01DEB01MODEB01PC04TA01WU01EA01LA01
412225DA02DEB01MODEB01PC04TA01WU01EA02LA02
512229DA01ACH01DEB01MODEB01PC04TA01WU01EA01LA04
612242DA03DEB02MODEB01PC04TA01WU01EA02LA02
712245DA04DEB02MODEB01PC04TA01WU01EA03LA05
812269DA01DEB03MODEB01PC04TA01WU01EA04LA01
912272DA01ACH01DEB01MODEB01PC04TA01WU01EA04LA01
1012282DA02DEB03MODEB01PC04TA01WU01EA05LA03
1112286DA05DEB01MODEB01PC04TA01WU01EA07LA07
1212289DA01ACH01DEB07MODEB01PC04TA01EA09LA09
13
Store Report


I'm trying to populate the account account number in column 1 of the "Transaction Type and Tender Type" sheet using the "Store Report" information. I'm limited to 64 nested if statements.


[/FONT]
 
Upvote 0
Re: Help with an If(And) with a Vlookup

Once you nest more than around 6 IF statements you should really be looking at constructing a table.

All your IFs staments consist of IF(AND(D2= something, C2= something), VLOOKUP(B2, 'Store Report'!A:J, column number, 0)
So...

in Sheet 2!A1:C64 construct a table, 64 rows by 3 columns wide

in column A put all the D2 condition text from your IF statments so reading down column A it should read

Cash
Cashier's Check
Money Order
etc

in Column B put all the C2 = condition text from your IF statements, so reading down column B it should read
Payment
Payment
Payment
etc

in Column C put the column number you want to retrieve from your IF statements so it should read
2
2
2
4
5
6
etc

Then replace that awful formula with

=IFERROR(VLOOKUP(B2,'Store Report'!A:J,INDEX(Sheet2!C$1:C$1000,MATCH(D2,IF(C2=Sheet2!B$1:B1000,Sheet2!A$1:A$1000)),1),0),"No")
Array formula, use Ctrl-Shift-Enter

If you need to add further conditions just enter more data into the table as the formula allows up to 1000 combinations
You just need the text for the D2 condition, text for the C2 condition and the column number to retrieve
No need to change the formula.
 
Last edited:
Upvote 0
Re: Help with an If(And) with a Vlookup

Wow, that actually worked. Good bye to the limited 64 nested if statements. Thanks for your help Special K. I've never seen an if statement nested in an index(match) like that. Super Cool! Thanks again. This topic can be closed!
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
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