Vlookup with IF

Pumperkin

Board Regular
Joined
Jan 24, 2019
Messages
59
Office Version
  1. 365
Platform
  1. Windows
Hi,

I am trying to do a Vlookup with IF, but just get a 0 answer rather than the result of the VLOOKUP.

I am trying to find (from a long list) the most expensive product in stock (the list includes in stock and sold items). I have a MAX(IF) array in cell K7 to find the highest value and am trying to find which product has that value.

The data itself is on a different sheet - the stock status is in Column 13 with the product details in Column 16 (however, the VLOOKUP starts in column 6 hence the number shifting).

I have the following formula:

Code:
=IF(Table3[Despatch Time]="Not Despatched", VLOOKUP(K7, Table3[[Cost]:[Model/Memory]], 11, ),)

Any ideas?
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
VLOOKUP(K7, Table3[[Cost]:[Model/Memory]], 11, )
so thats TRUE default and gets the nearest value,
Whats the range of Table3[[Cost]:[Model/Memory]] , the column number uses that as the reference
So 11 columns from [Cost] column

if you just use
VLOOKUP(K7, Table3[[Cost]:[Model/Memory]], 11, )
What do you get ?

I would have thought you needed
VLOOKUP(K7, Table3[[Cost]:[Model/Memory]], 11, FALSE)
OR
VLOOKUP(K7, Table3[[Cost]:[Model/Memory]], 11, TRUE) for the nearest vlaue
 
Upvote 0
VLOOKUP(K7, Table3[[Cost]:[Model/Memory]], 11, )
so thats TRUE default and gets the nearest value,
Whats the range of Table3[[Cost]:[Model/Memory]] , the column number uses that as the reference
So 11 columns from [Cost] column

if you just use
VLOOKUP(K7, Table3[[Cost]:[Model/Memory]], 11, )
What do you get ?

I would have thought you needed
VLOOKUP(K7, Table3[[Cost]:[Model/Memory]], 11, FALSE)
OR
VLOOKUP(K7, Table3[[Cost]:[Model/Memory]], 11, TRUE) for the nearest vlaue

Hi, Thanks for your reply. If I use the first formula I get the product with the highest value of all time, whether it's in stock or not. What I want to do is have an IF conditioner in there so it will only return the value of the most expensive product in stock (this is determined by "Despatch Time", row 8 from Cost, being "Not Despatched").
 
Upvote 0
why not use a MAX & IF , or if you have office 365 installed you can use MAXIFS()
do you have office 365
otherwise see here MAX with 2 criteria
 
Upvote 0
why not use a MAX & IF , or if you have office 365 installed you can use MAXIFS()
do you have office 365
otherwise see here MAX with 2 criteria

Hi, I have Office 2016.

I already have

VBA Code:
=MAX(IF(Table3[Despatch Time]="Not Despatched",Table3[Cost]))

As an array formula which returns the value £500.

What I want to do is find the product that is in stock that has that value.
 
Upvote 0
did you look at the link, which shows how to use 2 criteria
{=MAX(IF(rng1=criteria1,IF(rng2=criteria2,values)))}

So "not dispatched' and whatever K7 is

not sure if the table names are correct BUT, something like
=MAX ( IF( Table3[Despatch Time]="Not Despatched", IF ( Table3[[Cost] = K7 , Table3[Model/Memory] )))
 
Upvote 0
did you look at the link, which shows how to use 2 criteria
{=MAX(IF(rng1=criteria1,IF(rng2=criteria2,values)))}

So "not dispatched' and whatever K7 is

not sure if the table names are correct BUT, something like
=MAX ( IF( Table3[Despatch Time]="Not Despatched", IF ( Table3[[Cost] = K7 , Table3[Model/Memory] )))

Hi, Sorry that seemed to appear after I'd started typing my reply. I tried that (table names are right) but that just gave a 0 value. Not sure if that's right because I'm not finding the maximum value of the product make/model, but rather I'm finding the make/model with the max value in stock (so I need VLOOKUP I'd have thought?).
 
Upvote 0
ok, I did not understand the requirement
have a read here,
NOT sure how to translate your table names to the range
but i have an example here
BUT as you can see if you have 2 values that match you get the 1st one
Book1
ABCDE
1ProductStock StatusValue
2Item2out of stock1600Item14
3Item3out of stock2000
4Item4out of stock2400
5Item5out of stock2800
6Item6out of stock3200
7Item7out of stock3600
8Item8out of stock4000
9Item9out of stock4400
10Item10In Stock4800
11Item11out of stock5200
12Item12out of stock5600
13Item13out of stock6000
14Item14IN Stock6400
15Item15In stock6400
Sheet1
Cell Formulas
RangeFormula
E2E2=INDEX(A2:A100,MATCH(MAX(IF(B2:B100="in stock",C2:C100)),IF(B2:B100="in stock",C2:C100),0))
 
Upvote 0
Hi, Looks perfect will have a try and let you know :) Thanks for all your help :)
 
Upvote 0
Hmm I now get an error #N/A with Value not available.

I copied and pasted your formula but amended the parts as required:

Code:
=INDEX(Table3[Model/Memory],MATCH(MAX(IF(Table3[Despatch Time]="Not Depatched",Table3[Cost])),IF(Table3[Despatch Time]="Not Despatched",Table3[Cost]),0))

Think I'm getting closer...
 
Upvote 0

Forum statistics

Threads
1,215,004
Messages
6,122,659
Members
449,091
Latest member
peppernaut

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