Help me get away from nested IF/ANDs

cdterford

New Member
Joined
Jun 26, 2015
Messages
10
Excel 2010
Right now, I am working on a table that is going to count the amount of each part purchased. Then, I want to have a cell that will check which cell is highest, and report a cell that is adjacent to the highest one. It sounds complicated, but the picture should make it make sense. Currently, I can do this. BUT, I can only do it using messy, time-consuming nested IF/AND functions. I'm sure there is a simple way to do this with VLOOKUP, HLOOKUP, or INDEX/MATCH, but I really just have no idea how. Here's the ugly code I'm using; and there is a section that i haven't done yet with 9 (!) boxes, instead of this, which has 4 -- I would really like to not have to type all that out with nested IF/AND.

=IF(AND(H5>H6,H5>H7,H5>H8),G5,IF(AND(H6>H5,H6>H7,H6>H8),G6,IF(AND(H7>H5,H7>H6,H7>H8),G7,IF(AND(H8>H5,H8>H6,H8>H7),G8,""))))
This is the code I am using for J5 right now. As mentioned, this is all for only comparing 4 cells. The rows below have 9 to compare, and the code will get very long and messy.

2djowo2.png


This is the aforementioned picture. So, basically the "number purchased" column shows just that, by counting how many of each part is recorded in the blue area to the left. Simple. The "Most purchased" column is to look at the highest value from the "number purchased" column, and record the Model Number of that part (which is blacked out) that is in column G. In this instance, G3 and J3 say the same thing; G4 and L3 also say the same thing. Is there a simple way to do this without using the above nested IF code?

Thanks!
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
This works for all instances except where there is equal values within H5:H8. Yours would produce "". This produces the first found match:

=INDEX($G$5:$G$8,MATCH(MAX($H$5:$H$8),$H$5:$H$8,0))
 
Upvote 0
Hello,

What would be the result if two items are purchased at the same quantity ? Your formula would return blank.
 
Upvote 0
Your formula would return blank.

Yes, the intention would be to simply leave this blank if they were equal. It isn't a big deal, as the purpose of this is to be used for ALL sales of these parts. So, after about a week, there likely won't be an instance where they are all equal. Though I appreciate your concern!
 
Upvote 0
Steve's is right
=INDEX($G$5:$G$8,MATCH(MAX($H$5:$H$8),$H$5:$H$8,0))

If it is not set for Exact Match, it could actually fail for sort order issues.... (It's amazing how many times I forget to use it when I almost always need it.)
 
Upvote 0

Forum statistics

Threads
1,214,905
Messages
6,122,172
Members
449,071
Latest member
cdnMech

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