How can I change this formula?

michaelhunter

Board Regular
Joined
May 1, 2006
Messages
79
Hi folks,

GG26:GR26 contains simple formulas that produce values ranging from about 10 to 60 or so. These values change day to day.

GG27:GR27 also contains simple formulas that produce values ranging from 1 to 12. For example:

32 42 14 54 59 44 17 23 31 58 39 42
01 02 03 04 05 06 07 08 09 10 11 12
5

In GG28 I need the value in GG27:GR27 that corresponds to the highest one in GG26:GR26. In the example above, 59 is the highest value in GG26:GR26 and the number 5 is the corresponding value in GG27:GR27.

So in GG28 I have the formula:

=IF(ROWS($GG$28:GG28)<=COUNTIF($GG$26:$GR$26,MAX($GG$26:$GR$26)),
INDEX($GG$27:$GR$27,SMALL(IF($GG$26:$GR$26=MAX($GG$26:$GR$26),
COLUMN($GG$27:$GR$27)-COLUMN($GG$27)+1),ROWS($GG$28:GG28))),"")

entered with control+shift+enter and it returns the correct value: 5.

Now, in GH28 I need the value in GG27:GR27 that corresponds to the SECOND highest one in GG26:GR26. In the example, 58 would be the second highest value in GG26:GR26 and the corresponding value in GG27:GR27 is 10.

So in GH28 I would need that value: 10.

How can I modify the above formula to get it?

I've tried following a suggestion in a previous post but I haven't been able to make the right adjustment.

Once I know how to modify the formula, I think I can get the third, fourth and so on.

I would appreciate your suggestions.
 
Last edited:
Michael

Whilst the original Index formula that I supplied with adjustments by Peter SSs works apparently satisfactorily, if the case that there is 42 in cells 2 and 12 respectively is a true sample of your data then IMHO that formula does not produce the correct result!

Hopefully, the following does (in GG28 and copied across) -

Code:
=IF(AND((COLUMNS($GG$26:GG$26)>=2),LARGE($GG$26:$GR$26,COLUMNS($GG$26:GG$26))=LARGE($GG$26:$GR$26,COLUMNS($GG$26:GG$26)-(--(COLUMNS($GG$26:GG$26)>1)))),MATCH(LARGE($GG$26:$GR$26,COLUMNS($GG$26:GG$26)),OFFSET($GG$26,0,MATCH(LARGE($GG$26:$GR$26,COLUMNS($GG$26:GG$26)),$GG$26:$GR$26,0)+1,1,COLUMNS($GG$26:$GR$26)-MATCH(LARGE($GG$26:$GR$26,COLUMNS($GG$26:GG$26)),$GG$26:$GR$26,0)))+MATCH(LARGE($GG$26:$GR$26,COLUMNS($GG$26:GG$26)),$GG$26:$GR$26,0)+1,INDEX($GG$27:$GR$27,,MATCH(LARGE($GG$26:$GR$26,COLUMNS($GG$26:GG$26)),$GG$26:$GR$26,0)))

A brief explanation of the formula is as follows -

1. Test if the current column is > 1 and that the result of the LARGE formula for the current column equals the result of the LARGE formula for the previous column

2. Test is True then find the appropriate value in row 27 through MATCH statements determining the next instance of the value returned by the LARGE formula in that part of the array beginning one column to the right of the previous instance of the value returned by the LARGE formula.

3. Test is False by INDEX find the appropriate value in row 27

Please ask if you need more information about the solution.

@Armando - You didn't test your solution!

@Peter SSs - Thank you for your tip regarding handling the column offset.

Mike
 
Upvote 0

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Michael

You're welcome.

Just one last bit. I have managed to change the TRUE part of the formula to INDEX but it results in the formula being a lot larger!

Here is the final formula -
Code:
=IF(AND((COLUMNS($GG$26:GG$26)>=2),LARGE($GG$26:$GR$26,COLUMNS($GG$26:GG$26))=LARGE($GG$26:$GR$26,COLUMNS($GG$26:GG$26)-(--(COLUMNS($GG$26:GG$26)>1)))),INDEX(OFFSET($GG$27,0,MATCH(LARGE($GG$26:$GR$26,COLUMNS($GG$26:GG$26)),$GG$26:$GR$26,0)+1,1,COLUMNS($GG$26:$GR$26)-MATCH(LARGE($GG$26:$GR$26,COLUMNS($GG$26:GG$26)),$GG$26:$GR$26,0)),MATCH(LARGE($GG$26:$GR$26,COLUMNS($GG$26:GG$26)),OFFSET($GG$26,0,MATCH(LARGE($GG$26:$GR$26,COLUMNS($GG$26:GG$26)),$GG$26:$GR$26,0)+1,1,COLUMNS($GG$26:$GR$26)-MATCH(LARGE($GG$26:$GR$26,COLUMNS($GG$26:GG$26)),$GG$26:$GR$26,0)),0)),INDEX($GG$27:$GR$27,MATCH(LARGE($GG$26:$GR$26,COLUMNS($GG$26:GG$26)),$GG$26:$GR$26,0)))

Pleased to have helped you. It's been a bit of a learning curve for me too.

Good luck with your project.

Mike
 
Upvote 0
To deal with ties, consider using a helper 'Rank' row, which could be hidden if you want after formulas entered in it. The result is that much simpler formulas can be used. It should also cope with any number of ties.

Formulas copied across.

Excel Workbook
GFGGGHGIGJGKGLGMGNGOGPGQGR
26324214545944172331583942
27123456789101112
28Result510462121119873
29Rank851231411109276
Formula
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,909
Messages
6,175,313
Members
452,634
Latest member
cpostell

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