Finding exact text string in an array

gcefaloni

Board Regular
Joined
Mar 15, 2016
Messages
119
Hi guys,

I have a question regarding the best way to find the row number of a cell containing an exact string which in my example is a single letter. The problem I'm encountering is that this letter also happens to be within words of other cells. How would I go about returning only the row with the exact letter as a text string. The following table should help understand the situation

I'm using the following formula to search the array below:

=INDEX(Credit_Ratings,SMALL(IF(NOT(ISERROR(SEARCH(J6,Credit_Ratings))),ROW($1:$22),99^99),1),2)

J6 cell contains only the letter "A". The problem is that this letter also happens to be within the string AAA, AA+, A+, etc. However, I want the formula to return row number 7, not row number 2 because it finds an "A" within the "AAA" string in row 2. How would I go about modifying the above formula to return only the row for the exact content of cell J6 and nothing else?

RTG_SPRTG_DBRSRTG_MOODYRTG_FITCH
AAAAAAAaaAAA
AA+AAHAa1AA+
AAAAAa2AA
AA-AALAa3AA-
A+AHA1A+
AAA2A
A-ALA3A-
BBB+BBBHBaa1BBB+
BBBBBBBaa2BBB
BBB-BBBLBaa3BBB-
BB+BBHBa1BB+
BBBBBa2BB
BB-BBLBa3BB-
B+BHB1B+
BBB2B
B-BLB3B-
CCC+CCCHCaa1CCC
CCCCCCCaa2CCC
CCC-CCCLCaa3CCC
CCCCCaDDD
DDCDD

<tbody>
</tbody>


Thank you very much in advance!

P.S. =SUMPRODUCT((Credit_Ratings=J6)*(ROW(Credit_Ratings))) is a different way to go about it, but I encounter the same type of problem.
 
Last edited:

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Why not use MATCH?
Code:
=MATCH(J6,Credit_Ratings,0)

Hi jkpieterse,

Because it returns a #N/A. Not sure if it's because it is an array with multiple columns instead of a single column. Or because there are multiple instances of the letter "A" being present in the table even if they are all in the same row. It's the first thing I tried but it doesn't seem to work. I don't know if it's useful but the "Credit_Ratings" name represents the entire credit ratings table of A1 to D22.
 
Upvote 0
Maybe

=INDEX(Credit_Ratings,SMALL(IF(NOT(ISERROR(SEARCH("|"&J6&"|","|"&Credit_Ratings&"|"))),ROW($1:$22),99^99),1),1)
 
Upvote 0
Using @steve the fish's solution, but tweaked to match exact (Case)

=MIN(IF(EXACT($A$2:$D$22,J6),ROW($A$2:$D$22)))

It appears to work for me

Code:
[TABLE="width: 922"]
<colgroup><col width="97" style="width: 73pt;"><col width="87" span="4" style="width: 65pt;"><col width="129" style="width: 97pt;"><col width="87" span="4" style="width: 65pt;"></colgroup><tbody>[TR]
[TD="class: xl63, width: 97"]RTG_SP[/TD]
[TD="class: xl63, width: 87"]RTG_DBRS[/TD]
[TD="class: xl63, width: 87"]RTG_MOODY[/TD]
[TD="class: xl63, width: 87"]RTG_FITCH[/TD]
[TD="width: 87"][/TD]
[TD="width: 129"][/TD]
[TD="width: 87"][/TD]
[TD="width: 87"][/TD]
[TD="width: 87"][/TD]
[TD="width: 87"][/TD]
[/TR]
[TR]
[TD="class: xl63"]AAA[/TD]
[TD="class: xl63"]AAA[/TD]
[TD="class: xl63"]Aaa[/TD]
[TD="class: xl63"]AAA[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="class: xl63"]AA+[/TD]
[TD="class: xl63"]AAH[/TD]
[TD="class: xl63"]Aa1[/TD]
[TD="class: xl63"]AA+[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="class: xl63"]AA[/TD]
[TD="class: xl63"]AA[/TD]
[TD="class: xl63"]Aa2[/TD]
[TD="class: xl63"]AA[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="class: xl63"]AA-[/TD]
[TD="class: xl63"]AAL[/TD]
[TD="class: xl63"]Aa3[/TD]
[TD="class: xl63"]AA-[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="class: xl63"]A+[/TD]
[TD="class: xl63"]AH[/TD]
[TD="class: xl63"]A1[/TD]
[TD="class: xl63"]A+[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]A[/TD]
[/TR]
[TR]
[TD="class: xl63"]A[/TD]
[TD="class: xl63"]A[/TD]
[TD="class: xl63"]A2[/TD]
[TD="class: xl63"]A[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]Row[/TD]
[TD="class: xl63, align: right"]7[/TD]
[/TR]
[TR]
[TD="class: xl63"]A-[/TD]
[TD="class: xl63"]AL[/TD]
[TD="class: xl63"]A3[/TD]
[TD="class: xl63"]A-[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="class: xl63"]BBB+[/TD]
[TD="class: xl63"]BBBH[/TD]
[TD="class: xl63"]Baa1[/TD]
[TD="class: xl63"]BBB+[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="class: xl63"]BBB[/TD]
[TD="class: xl63"]BBB[/TD]
[TD="class: xl63"]Baa2[/TD]
[TD="class: xl63"]BBB[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="class: xl63"]BBB-[/TD]
[TD="class: xl63"]BBBL[/TD]
[TD="class: xl63"]Baa3[/TD]
[TD="class: xl63"]BBB-[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="class: xl63"]BB+[/TD]
[TD="class: xl63"]BBH[/TD]
[TD="class: xl63"]Ba1[/TD]
[TD="class: xl63"]BB+[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="class: xl63"]BB[/TD]
[TD="class: xl63"]BB[/TD]
[TD="class: xl63"]Ba2[/TD]
[TD="class: xl63"]BB[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="class: xl63"]BB-[/TD]
[TD="class: xl63"]BBL[/TD]
[TD="class: xl63"]Ba3[/TD]
[TD="class: xl63"]BB-[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="class: xl63"]B+[/TD]
[TD="class: xl63"]BH[/TD]
[TD="class: xl63"]B1[/TD]
[TD="class: xl63"]B+[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="class: xl63"]B[/TD]
[TD="class: xl63"]B[/TD]
[TD="class: xl63"]B2[/TD]
[TD="class: xl63"]B[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="class: xl63"]B-[/TD]
[TD="class: xl63"]BL[/TD]
[TD="class: xl63"]B3[/TD]
[TD="class: xl63"]B-[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="class: xl63"]CCC+[/TD]
[TD="class: xl63"]CCCH[/TD]
[TD="class: xl63"]Caa1[/TD]
[TD="class: xl63"]CCC[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="class: xl63"]CCC[/TD]
[TD="class: xl63"]CCC[/TD]
[TD="class: xl63"]Caa2[/TD]
[TD="class: xl63"]CCC[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="class: xl63"]CCC-[/TD]
[TD="class: xl63"]CCCL[/TD]
[TD="class: xl63"]Caa3[/TD]
[TD="class: xl63"]CCC[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="class: xl63"]CC[/TD]
[TD="class: xl63"]CC[/TD]
[TD="class: xl63"]Ca[/TD]
[TD="class: xl63"]DDD[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="class: xl63"]D[/TD]
[TD="class: xl63"]D[/TD]
[TD="class: xl63"]C[/TD]
[TD="class: xl63"]DD[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
 
Last edited:
Upvote 0
Maybe

=INDEX(Credit_Ratings,SMALL(IF(NOT(ISERROR(SEARCH("|"&J6&"|","|"&Credit_Ratings&"|"))),ROW($1:$22),99^99),1),1)

This seems to work! What do the "|" do? I had tried SEARCH(" "&J6&" "," "&Credit_Ratings&" ")) without avail.

Thanks!
 
Upvote 0
I'm just concatenating | with the look up value, so A becomes |A|, the array showing A becomes |A| whilst AAA becomes |AAA|.

Problem is it is not case sensitive, use Find instead of search.

And Steve's solution works for me and is much neater.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,545
Messages
6,120,128
Members
448,947
Latest member
test111

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