Home » excel » vba – Excel | Index Match |

vba – Excel | Index Match |

Posted by: admin May 14, 2020 Leave a comment

Questions:

I require your assistance on the following:

Lets say we got 3 different groups: (A,B,C)

And we have a few value ranges within each group:

(Eg. A has 0 - 100, 101 - 200 while B has 0 - 200, 201 - 400 and C has 0 - 300, 301 - 600.)

At the end, for each group that falls under whatever range they have, they will be assigned a final number.
(Eg.

[A,95] = 0.5 / [A,101] = 1.0
[B,95] = 1.5 / [B,205] = 3.0
[C,95] = 4.5 / [C,308] = 6.0)

Currently i have my index match formula as follows:

"=INDEX(finalnumber!F2:F29,MATCH(C11&C25,Group!A2:A29&valuerange!D2:D29,0))"

I keep getting a #N/A response.

I have also created an array table as follows:

enter image description here

Group    Range    Final Number
A        0 - 100      0.50
A        101 - 200    1.00
B        0 - 200      1.50
B        201 - 400    3.00
C        0 - 300      4.50
C        301 - 600    6.00

Pls help! Many thanks in advance!

How to&Answers:

You can use the following (you will need to tailor to your layout). I have assumed A and 95, for example, are in separate cells as you concatenate cells in your formula to do your lookup.

=IF(AND(ISERROR(INDEX(OFFSET(INDEX(C:C,H2),,,I2-H2+1,1),MATCH(VLOOKUP(G2,LEFT(OFFSET(INDEX(B:B,H2),,,I2-H2+1,1),FIND("-",OFFSET(INDEX(B:B,H2),,,I2-H2+1,1))-1)*1,TRUE),LEFT(OFFSET(INDEX(B:B,H2),,,I2-H2+1,1),FIND("-",OFFSET(INDEX(B:B,H2),,,I2-H2+1,1))-1)*1,0))),INDEX(A:A,COUNTA(A:A)+1)=F2,G2>=1*LEFT(INDEX(B:B,COUNTA(A:A)+1),FIND("-",INDEX(B:B,COUNTA(A:A)+1))-1),G2<=1*RIGHT(INDEX(B:B,COUNTA(A:A)+1),LEN(INDEX(B:B,COUNTA(A:A)+1)) - FIND("-",INDEX(B:B,COUNTA(A:A)+1)))),INDEX(C:C,COUNTA(A:A)+1),INDEX(OFFSET(INDEX(C:C,H2),,,I2-H2+1,1),MATCH(VLOOKUP(G2,LEFT(OFFSET(INDEX(B:B,H2),,,I2-H2+1,1),FIND("-",OFFSET(INDEX(B:B,H2),,,I2-H2+1,1))-1)*1,TRUE),LEFT(OFFSET(INDEX(B:B,H2),,,I2-H2+1,1),FIND("-",OFFSET(INDEX(B:B,H2),,,I2-H2+1,1))-1)*1,0)))

This is entered as an array formula with Ctrl+ Shift+ Enter

Formulas in helper cells (to keep overall formula more legible):

H2 is =MATCH(F2,A:A,0) ‘ finds the first match for the letter e.g. A

I2 is =MAX(IF(A:A=F2,ROW(A:A)-ROW(INDEX(A:A,1,1))+1)) ‘ finds the last match for the letter e.g. A. This is entered with Ctrl+ Shift+ Enter i.e. an array formula.


Data layout

data

Example run:

test run


Notes:

You might want to wrap the whole thing in an IFERROR( formula, "") to hide any not found error messages.

Answer:

I’m unclear why you require four separate worksheets for this operation. For simplicity in demonstrating, I’ve put your lookup table on the same worksheet as the values to lookup.

=SUMPRODUCT(I$2:I$7, (G$2:G$7=LEFT(A2))*(--REPLACE(H$2:H$7, FIND(" - ", H$2:H$7), 9, TEXT(,))<=--MID(A2, 3, 9))*
                                        (--REPLACE(H$2:H$7, 1, FIND(" - ", H$2:H$7)+1, TEXT(,))>=--MID(A2, 3, 9)))

enter image description here