Need to Index/Match based on Two Criteria in same row

mhs321

New Member
Joined
Mar 24, 2020
Messages
4
Office Version
  1. 2013
Platform
  1. Windows
Hello, Excel wizards, I hope you are doing well.

I am trying to use Index/Match To locate the Nth instance of specific text.
The catch:
Nth instance can change
Both Criteria are in Col A

What I want to locate: Service ID for IDS where the Access number is 111111111 (Purple cell, Col A, in the pic)

Match to find *111111111* - check, Locates first instance (A6)
Match to find IDS - check, Locates first instance (A2)

I need to figure out how to tell Excel to find at each instance of the Access Number and look at the Row above it.
If/When Excel finds a cell that contains "IDS" then return the text in that cell.


K11 = Access Number
Access Number Minus 1 ROW = INDEX($A:$A,MATCH("*"&K11&"*",$A:$A,0)-1,1)

Final Code Format:
=INDEX(A:A,MATCH(1,Two Criteria,0),1)

Two Criteria = (A:A=Access Number Minus 1 ROW) * (A:A="IDS*")
(A:A=INDEX($A:$A,MATCH("*"&K11&"*",$A:$A,0)-1,1)) * (A:A="IDS*")

Closest I have to final code is:
=INDEX(A:A,MATCH(1,(A:A=INDEX($A:$A,MATCH("*"&K11&"*",$A:$A,0)-1,1)) * (A:A="IDS*"),0),1)

This isn't right because (Access Num - 1) = A5 & IDS* = A2

Stuck on how to get the two to triangulate properly and move down to each next instance of the Access Number.

Thanks.
 

Attachments

  • Image 2.png
    Image 2.png
    58.6 KB · Views: 10

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
I think you want something like

=INDEX(A:A,match("IDS*",$A$1:INDEX(A:A,MATCH("*"&K11&"*",$A:$A,0)-1),0))

It is better if you post examples using XL2BB (button on reply box toolbar), screen captures can not be used for testing formulas without retyping your data into excel first, if you use XL2BB we can copy and paste your data and formulas straight into a blank sheet.
 
Upvote 0
Thank you for the tip about XL2BB. I had no idea. Great feature.

I tried the code you provided and it produced #N/A
Evaluating the formula it read
INDEX($A:$A, MATCH("IDS*",$A$1,0))
INDEX($A:$A, #N/A)

I have attached my XL2BB for further review.

Went for a drive. Now I'm thinking I need to use an IF/THEN statement to move it to the next instance.

Invoice Code - MHS.xlsx
ABCDEFGHIJ
1CircuitRelated AccessCircuit TypeService ID Contract/SOF NumberAccess Circuit ID
2IDSC1234567111111111Private IP (PIP)616161616212121E5555555
3C0999999777777777Private IP (PIP)313131313212121E4444444
4111111111 E5555555
5DescriptionCharge Period
6Access - Service ID: 111111111 Contract/SOF Number: D01234-00Match
7Circuit ID: E5555555IDSIDS2
8Local Access - Op/App Performance:
9Platinum / Platinum - 10 Mbps - UNI Speed:
101 Gbps (GigE)
11Total 111111111 Access111111111Access - Service ID: 111111111 Contract/SOF Number: D01234-00
122
13Access - Service ID: 777777777 Contract/SOF Number: D01234-00#N/A
14Circuit ID: E4444444
15Local Access - Op/App Performance:
16Platinum / Platinum - 10 Mbps - UNI Speed:#N/A
171 Gbps (GigE)
18Total 777777777 Access
19
20IDS - Service ID: 979797979 Contract/SOF Number: 212121
21Related Service: Access 111111111
22Internet Dedicated Port - Tiered - 3 Mbps
23Total 979797979 IDS
24
25IDS - Service ID: 987654321 Contract/SOF Number: 212121
26Related Service: Access 777777777
27Internet Dedicated Port - Tiered - 3 Mbps
28Total 987654321 IDS
29
30Private IP (PIP) - Service ID: 616161616 Contract/SOF Number: 212121
31Circuit ID: C1234567
32Related Service: Access 111111111
33PIP Port - 2 Mbps - United States
34Total 616161616 Private IP (PIP)
35
36Private IP (PIP) - Service ID: 313131313 Contract/SOF Number: 212121
37Circuit ID: C0999999
38Related Service: Access 777777777
39PIP Port - 2 Mbps - United States
40Total 313131313 Private IP (PIP)
41Total 2537518C
42
43
Sheet1
Cell Formulas
RangeFormula
G2:G3G2=LEFT(INDEX($A:$A,MATCH("*"&E2&"*",$A:$A,0)-1,1), FIND("-",(INDEX($A:$A,MATCH("*"&E2&"*",$A:$A,0)-1,1)),1)-2)
H2:H3H2=MID(INDEX($A:$A,MATCH("*"&E2&"*",$A:$A,0)-1,1), FIND("Service ID:",INDEX($A:$A,MATCH("*"&E2&"*",$A:$A,0)-1,1),1)+LEN("Service ID: "), (FIND("Contract/SOF",INDEX($A:$A,MATCH("*"&E2&"*",$A:$A,0)-1,1),1)-3)-(FIND("Service ID:",INDEX($A:$A,MATCH("*"&E2&"*",$A:$A,0)-1,1),1)+LEN("Service ID: ")-1))
I2:I3I2=RIGHT(INDEX($A:$A,MATCH("*"&E2&"*",$A:$A,0)-1,1), LEN(INDEX($A:$A,MATCH("*"&E2&"*",$A:$A,0)-1,1)) - (FIND("Contract/SOF",INDEX($A:$A,MATCH("*"&E2&"*",$A:$A,0)-1,1),1)+LEN("Contract/SOF Number: ")-1))
J2:J3J2=RIGHT(INDEX(A:A,MATCH("*"&F2&"*",A:A,0)+1,1),8)
F2F2=RIGHT(INDEX($A:$A,MATCH("*"&E2&"*",$A:$A,0)+1,1),9)
F3:F4F3=RIGHT(INDEX(A:A,MATCH("*"&E3&"*",A:A,0)+1,1),9)
F7F7=INDEX(A:A,MATCH("*"&E7&"*",A:A,0),1,1)
G7G7=MATCH("*" & "IDS" & "*",A:A,0)
F11F11=INDEX($A:$A,MATCH("*"&E11&"*",$A:$A,0),1,1)
F12F12=MATCH("*" & "IDS" & "*",A:A,0)
F13F13=INDEX(A:A,MATCH(1,(A:A=INDEX($A:$A,MATCH("*"&K11&"*",$A:$A,0)-1,1)) * (A:A="IDS*"),0),1)
F16F16=INDEX(A:A,MATCH("IDS*",$A$1:INDEX(A:A,MATCH("*"&K11&"*",$A:$A,0)-1),0))
Cells with Conditional Formatting
CellConditionCell FormatStop If True
A3:A41Cell Valuecontains "223227766"textNO
A3:A41Cell Valuecontains "223227758"textNO
A3:A41Cell Valuecontains "C0141065"textNO
A3:A41Cell Valuecontains "223227758"textNO
 
Upvote 0
I followed the references from the formulas in post 1, but looking at the above, I think that you just need to change K11 to E11 to make it work

=INDEX(A:A,match("IDS*",$A$1:INDEX(A:A,MATCH("*"&E11&"*",$A:$A,0)-1),0))

Unless I'm having a serious case of brainfart.
 
Upvote 0
That did not work. The address correction was needed but the function is flawed.
The INDEX for the Access Number finds the first instance and returns the Row above = "Description"
The MATCH for *IDS* finds the first instance and returns the cell address = 2
"Description" * 2 = #VALUE!

Evaluation is below.

So I went back and thought about what I am needing Excel to do:
MATCH(Access#)
Look at the Row above for "IDS*"
True = Return value of Row above
False = Move to next instance of Access#
Repeat Until True
or
Return NULL if never True


What I need is a "Do Until Loop"
I haven't written VBA in Excel.
I have in Access but not Excel. I realize it's the same thing but I'm a bit rusty.
Time to knock off the cobwebs...Youtube is my friend.

As always, open to any VBA code suggestions

Thanks.

Here is the Evaluation:
INDEX(A:A,MATCH(1,INDEX((INDEX($A:$A,MATCH("*"&E11&"*",$A:$A,0)-1,1)) * (MATCH("*" & "IDS" & "*",A:A,0)),0,1),0))
INDEX($A:$A,MATCH(1,INDEX((INDEX($A:$A,MATCH("*"&111111111&"*",$A:$A,0)-1,1)) * (MATCH("*" & "IDS" & "*",A:A,0)),0,1),0))
INDEX($A:$A,MATCH(1,INDEX((INDEX($A:$A,MATCH("*111111111*",$A:$A,0)-1,1)) * (MATCH("*" & "IDS" & "*",A:A,0)),0,1),0))
INDEX($A:$A,MATCH(1,INDEX((INDEX($A:$A,6-1,1)) * (MATCH("*" & "IDS" & "*",A:A,0)),0,1),0))
INDEX($A:$A,MATCH(1,INDEX((INDEX($A:$A,5,1)) * (MATCH("*" & "IDS" & "*",A:A,0)),0,1),0))
INDEX($A:$A,MATCH(1,INDEX(("Description") * (MATCH("*" & "IDS" & "*",A:A,0)),0,1),0))
INDEX($A:$A,MATCH(1,INDEX(("Description") * (MATCH("*IDS*",A:A,0)),0,1),0))
INDEX($A:$A,MATCH(1,INDEX(("Description") * (2),0,1),0))
INDEX($A:$A,MATCH(1,INDEX(("Description" * 2),0,1),0))
INDEX($A:$A,MATCH(1,INDEX((#VALUE!,0,1),0))
 
Upvote 0
Sorry, it wasn't the function that was flawed, it was definitely me having a full scale nuclear brainfart.

I think that I can see what you need now, going to put something together now just to make sure that I'm on the right track, then we can refine it a bit if needed.
 
Upvote 0
See if this formula does what you need,

=IFERROR(INDEX(A:A,AGGREGATE(15,6,ROW($A$5:$A$40)/ISNUMBER(SEARCH($E$11,$A$6:$A$41))/ISNUMBER(SEARCH("IDS",$A$5:$A$40)),1)),"No Match")

If you modify the formula for another sheet, note that the INDEX range refers to the entire column, the ROW and second SEARCH ranges refer to the actual data range excluding the last row, the first SEARCH range refers to the actual data range excluding the first row. This is probably the easiest way to check for pairs of rows meeting criteria, I suspect that looping in vba would be considerably slower.
 
Upvote 0
Ooooo!! Functions I have never used.
Thank you, that worked, btw.

I researched AGGREGATE and I have dissected this formula and this is quite brilliant.
Thank you for showing me a new trick!!
 
Upvote 0

Forum statistics

Threads
1,224,833
Messages
6,181,240
Members
453,026
Latest member
cknader

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