Vlookup with nested IF function

JohnZ1156

Board Regular
Joined
Apr 10, 2021
Messages
153
Office Version
  1. 2021
Platform
  1. Windows
I have a data table with dates in column A and values in column B.
In cell C1 I enter the date for the Vlookup.
I would like to use Vlookup to search for a date in column A and return the corresponding value in column B.

Now,
Some dates may not have a corresponding value in column B. (an empty cell)
If the date found by Vlookup has no corresponding value in column B, I'd like it to return the Previous days value.
If THAT date has no corresponding value, I'd like it to return the NEXT Previous days value, and so on.

I tried a nested IF function with Vlookup something like this:
I was trying to get it to go to the prior date when no value was found.

=IF(VLOOKUP(C1,Table1,2)=0,VLOOKUP(C1-1,Table1,2),IF(VLOOKUP(C1-1,Table1,2)=0,VLOOKUP(C1-2,Table1,2),IF(VLOOKUP(C1-2,Table1,2)=0,VLOOKUP(C1-3,Table1,2),IF(VLOOKUP(C1-3,Table1,2)=0,VLOOKUP(C1-4,Table1,2),IF(VLOOKUP(C1-4,Table1,2)=0,VLOOKUP(C1-5,Table1,2),IF(VLOOKUP(C1-5,Table1,2)=0,VLOOKUP(C1-6,Table1,2),IF(VLOOKUP(C1-6,Table1,2)=0,VLOOKUP(C1-7,Table1,2),VLOOKUP(C1,Table1,2))))))))

VLookup Test.jpg


Thanks for your help in advance.
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
How about like
+Fluff 1.xlsm
HIJKL
1DateAmount
220/12/2021128/12/20214
321/12/20212
422/12/20213
523/12/20214
624/12/2021
725/12/2021
826/12/2021
927/12/2021
1028/12/2021
1129/12/202110
1230/12/202111
1331/12/202112
1401/01/202213
1502/01/202214
1603/01/202215
1704/01/202216
1805/01/202217
19
Main
Cell Formulas
RangeFormula
L2L2=LOOKUP(2,1/(I2:INDEX(Table1[Amount],MATCH(K2,Table1[Date],0))<>""),I2:INDEX(Table1[Amount],MATCH(K2,Table1[Date],0)))
 
Upvote 0
Solution
Hi Fluff,

That works great !! Thank you.
Being an old Lotus 1-2-3 User, I'm not familiar with the "Lookup" Function.

I do have another question which I thought I'd be able to figure out from your formula.

Is is possible to "go the other way"?
In other words, this formula goes backwards and returns the values for the previous day(s).

Can we also have a formula that would go forward and return the value for the day(s) AFTER the date with no value?

I'm not fluent enough in excel to "reverse" your great formula.
Thanks again, John
 
Upvote 0
How about
Excel Formula:
=INDEX(Table1[Amount],AGGREGATE(15,6,(ROW(Table1[Amount])-ROW(Table1[[#Headers],[Amount]]))/(Table1[Date]>=K2)/(Table1[Amount]<>""),1))
 
Upvote 0
How about
Excel Formula:
=INDEX(Table1[Amount],AGGREGATE(15,6,(ROW(Table1[Amount])-ROW(Table1[[#Headers],[Amount]]))/(Table1[Date]>=K2)/(Table1[Amount]<>""),1))
I have no idea how this works, but it does !!! Thank you.
I would NEVER have been able to come up with this formula by looking at your first formula.
Thank you very much, again !!!
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,826
Messages
6,121,795
Members
449,048
Latest member
greyangel23

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