Nested Ifs Based on the Calendar Year

tycasey17

Board Regular
Joined
Sep 26, 2013
Messages
64
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
I have been trying to have a nested IF statement based on the year. It seems like the year portion is causing the issue but I cannot seem how to fix this, I am trying to have multiple years on the same sheet but have a formula to pull up by the year I select.


SAMPLE FORMULA:
IF(A1="2019",
IF(VLOOKUP(A2,B2:D10,2,FALSE)="YES","YES",
IF(VLOOKUP(A2,B2:D10,2,FALSE)="NO","NO","")),
IF(A1="2020",
IF(VLOOKUP(A2,B2:D10,3,FALSE)="YES","YES",
IF(VLOOKUP(A2,B2:D10,3,FALSE)="NO","NO","")),""))
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
57,030
Office Version
  1. 365
Platform
  1. Windows
Why not simply
IF(A1=2019,VLOOKUP(A2,B2:D10,2,FALSE),IF(A1=2020,VLOOKUP(A2,B2:D10,3,FALSE),""))
 

tycasey17

Board Regular
Joined
Sep 26, 2013
Messages
64
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
There will be more than just two arguments, it will end up being about five per year so I see what you mean.
 

jtakw

Well-known Member
Joined
Jun 29, 2014
Messages
6,007
Office Version
  1. 2016
Platform
  1. Windows
Hi,

If you have the Year as a Number (Not Text) in A1, have you removed the quote marks around "2019", and "2020" in your formula like Fluff show in Post # 2 ?
If you have, then it should work.

Also, if you use a "Helper Cell" to convert the Year in A1 (2019, 2020) to 2, 3 respectively, your formula can be cut in half (or more), if you add more years, (i.e. 2019, 2020, 2021, 2022 to 2, 3, 4, 5).

See below sample:

<b></b><table cellpadding="2.5px" rules="all" style=";background-color: rgb(255,255,255);border: 1px solid;border-collapse: collapse; border-color: rgb(187,187,187)"><colgroup><col width="25px" style="background-color: rgb(218,231,245)" /><col /><col /><col /><col /><col /><col /><col /></colgroup><thead><tr style=" background-color: rgb(218,231,245);text-align: center;color: rgb(22,17,32)"><th></th><th>A</th><th>B</th><th>C</th><th>D</th><th>E</th><th>F</th><th>G</th></tr></thead><tbody><tr ><td style="color: rgb(22,17,32);text-align: center;">1</td><td style="text-align: right;;">2019</td><td style="text-align: right;;">2</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style=";">YES</td><td style=";">YES</td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">2</td><td style=";">some</td><td style=";">this</td><td style=";">a</td><td style=";">b</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">3</td><td style="text-align: right;;"></td><td style=";">that</td><td style=";">b</td><td style=";">c</td><td style="text-align: right;;"></td><td style=";">^Your formula</td><td style=";">Shortened using B1</td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">4</td><td style="text-align: right;;"></td><td style=";">some</td><td style=";">yes</td><td style=";">no</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">5</td><td style="text-align: right;;"></td><td style=";">other</td><td style=";">c</td><td style=";">d</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">6</td><td style="text-align: right;;"></td><td style=";">yes</td><td style=";">d</td><td style=";">e</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">7</td><td style="text-align: right;;"></td><td style=";">no</td><td style=";">e</td><td style=";">f</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">8</td><td style="text-align: right;;"></td><td style=";">maybe</td><td style=";">f</td><td style=";">g</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">9</td><td style="text-align: right;;"></td><td style=";">high</td><td style=";">g</td><td style=";">h</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">10</td><td style="text-align: right;;"></td><td style=";">low</td><td style=";">h</td><td style=";">i</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr></tbody></table><p style="width:6.4em;font-weight:bold;margin:0;padding:0.2em 0.6em 0.2em 0.5em;border: 1px solid rgb(187,187,187);border-top:none;text-align: center;background-color: rgb(218,231,245);color: rgb(22,17,32)">Sheet554</p><br /><br /><table width="85%" cellpadding="2.5px" rules="all" style=";border: 2px solid black;border-collapse:collapse;padding: 0.4em;background-color: rgb(255,255,255)" ><tr><td style="padding:6px" ><b>Worksheet Formulas</b><table cellpadding="2.5px" width="100%" rules="all" style="border: 1px solid;text-align:center;background-color: rgb(255,255,255);border-collapse: collapse; border-color: rgb(187,187,187)"><thead><tr style=" background-color: rgb(218,231,245);color: rgb(22,17,32)"><th width="10px">Cell</th><th style="text-align:left;padding-left:5px;">Formula</th></tr></thead><tbody><tr><th width="10px" style=" background-color: rgb(218,231,245);color: rgb(22,17,32)">B1</th><td style="text-align:left">=IF(<font color="Blue">A1=2019,2,IF(<font color="Red">A1=2020,3,""</font>)</font>)</td></tr><tr><th width="10px" style=" background-color: rgb(218,231,245);color: rgb(22,17,32)">F1</th><td style="text-align:left">=IF(<font color="Blue">A1=2019,IF(<font color="Red">VLOOKUP(<font color="Green">A2,B2:D10,2,FALSE</font>)="YES","YES",IF(<font color="Green">VLOOKUP(<font color="Purple">A2,B2:D10,2,FALSE</font>)="NO","NO",""</font>)</font>),IF(<font color="Red">A1=2020,IF(<font color="Green">VLOOKUP(<font color="Purple">A2,B2:D10,3,FALSE</font>)="YES","YES",IF(<font color="Purple">VLOOKUP(<font color="Teal">A2,B2:D10,3,FALSE</font>)="NO","NO",""</font>)</font>),""</font>)</font>)</td></tr><tr><th width="10px" style=" background-color: rgb(218,231,245);color: rgb(22,17,32)">G1</th><td style="text-align:left">=IFERROR(<font color="Blue">IF(<font color="Red">VLOOKUP(<font color="Green">A2,B2:D10,B1,FALSE</font>)="YES","YES",IF(<font color="Green">VLOOKUP(<font color="Purple">A2,B2:D10,B1,FALSE</font>)="NO","NO",""</font>)</font>),""</font>)</td></tr></tbody></table></td></tr></table><br />
 
Last edited:

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
57,030
Office Version
  1. 365
Platform
  1. Windows
Or without a helper cell
=IFERROR(IF(VLOOKUP(A2,B2:D10,A1-2017,0)="yes","YES",IF(VLOOKUP(A2,B2:D10,A1-2017,0)="no","NO","")),"")
 

Watch MrExcel Video

Forum statistics

Threads
1,130,446
Messages
5,642,204
Members
417,261
Latest member
andrewd1

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