Lookup one value in two lists and identify corresponding values

khawarameer

Board Regular
Joined
Jun 2, 2009
Messages
152
Hello All,

I am looking for a formula which will look a value from a two lists and list its corresponding value in result.
Please refer the table below

Lookup Value
Item_1 List1Lsit2
Item_1Item_2
Item_3Item_1
Item_1Item_3
Item_2Item_1
Item_4Item_2
Item_3Item_4
Result
Item_2
Item_3

<thead>
</thead><tbody>
</tbody>


Please help.

Regards
 
Last edited:

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Re: Lookup one vaule in two lists and identify corresponding values

Here is one way. C12 is an array formula so should be entered without the {} but confirmed with Ctrl+Shift+Enter, not just Enter. If confirmed correctly, Excel will insert the {}. The formula can then be copied down as far as you might ever need.


Excel 2010 32 bit
ABCD
1Lookup Value
2Item_1List1Lsit2
32Item_1Item_2
4Item_3Item_1
5Item_1Item_3
6Item_2Item_1
7Item_4Item_2
8Item_3Item_4
9
10
11Result
12Item_2
13Item_3
14
List all
Cell Formulas
RangeFormula
A3=COUNTIF(C3:C8,A2)
C12{=IF(ROWS(C$12:C12)>A$3,"",INDEX(D$3:D$8,SMALL(IF(C$3:C$8=A$2,ROW(C$3:C$8)-ROW(C$3)+1),ROWS(C$12:C12))))}
Press CTRL+SHIFT+ENTER to enter array formulas.
 
Upvote 0
Re: Lookup one vaule in two lists and identify corresponding values

Here is one way. C12 is an array formula so should be entered without the {} but confirmed with Ctrl+Shift+Enter, not just Enter. If confirmed correctly, Excel will insert the {}. The formula can then be copied down as far as you might ever need.

Excel 2010 32 bit
ABCD
1Lookup Value
2Item_1List1Lsit2
32Item_1Item_2
4Item_3Item_1
5Item_1Item_3
6Item_2Item_1
7Item_4Item_2
8Item_3Item_4
9
10
11Result
12Item_2
13Item_3
14

<colgroup><col style="width: 25pxpx"><col><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
List all

Worksheet Formulas
CellFormula
A3=COUNTIF(C3:C8,A2)

<thead>
</thead><tbody>
</tbody>

<tbody>
</tbody>

Array Formulas
CellFormula
C12{=IF(ROWS(C$12:C12)>A$3,"",INDEX(D$3:D$8,SMALL(IF(C$3:C$8=A$2,ROW(C$3:C$8)-ROW(C$3)+1),ROWS(C$12:C12))))}

<thead>
</thead><tbody>
</tbody>
Entered with Ctrl+Shift+Enter. If entered correctly, Excel will surround with curly braces {}.
Note: Do not try and enter the {} manually yourself

<tbody>
</tbody>

Hi Peter_SSs

Thanks for your response. However there i needed the formula that would check both List_1 & List_2 and show the resulting value only once i.e. No repetition.

Can you please help.

Regards
 
Upvote 0
Re: Lookup one vaule in two lists and identify corresponding values

However there i needed the formula that would check both List_1 & List_2 and show the resulting value only once i.e. No repetition.
So that I can better understand, could you then give some sample data and expected results where my formula does not produce those expected results?


BTW, best not to fully quote long posts as it makes the thread harder to read/navigate and just occupies storage space needlessly. If you want to quote, quote small, relevant parts only.
 
Upvote 0
Re: Lookup one vaule in two lists and identify corresponding values

Hi Peter_SSs,

Thanks for your response. Your suggestion is noted [Thanks]. Here is some sample data as you suggested, hopefully this will be sufficient.

1ABC
2Look_Up_Value
3Khawar
4 List_1List_2
5 KhawarTahami
6 KhawarIqbal
7 KhawarImran
8 KhawarZain
9 KhawarTahami
10 KhawarIqbal
11 ZainKhawar
12 TahamiKhawar
13 IqbalKhawar
14 TahamiKhawar
15 ImranKhawar
16 ZainKhawar
17
18 ResultResult Count
19 Tahami4
20 Iqbal3
21 Imran2
22 Zain3

<thead>
</thead><tbody>
</tbody>


Thanks and regards
 
Last edited:
Upvote 0
Re: Lookup one vaule in two lists and identify corresponding values

Here is some sample data as you suggested, hopefully this will be sufficient.
Here is one possible solution that employs a user-defined function in one column and a standard worksheet formula in another. To implement the udf ..

1. Right click the sheet name tab and choose "View Code".
2. In the Visual Basic window use the menu to Insert|Module
3. Copy and Paste the code below into the main right hand pane that opens at step 2.
4. Close the Visual Basic window.
5. Enter the formula as shown in B18 in the screen shot below and copy down.
6. Your workbook will need to be saved as a macro-enabled workbook (*.xlsm)

Rich (BB code):
Function GetName(r As Range, lookupname As String, num As Long) As String
  Dim d As Object
  Dim a As Variant
  Dim i As Long, k As Long
  Dim s As String
  
  Set d = CreateObject("Scripting.Dictionary")
  d.CompareMode = 1
  a = r.Value
  For i = 1 To UBound(a)
    s = vbNullString
    If a(i, 1) = lookupname Then
      s = a(i, 2)
    ElseIf a(i, 2) = lookupname Then
      s = a(i, 1)
    End If
    If Len(s) > 0 And Not d.exists(s) Then
      d(s) = 1
      k = k + 1
      If k = num Then
        GetName = s
        Exit For
      End If
    End If
  Next i
End Function

Formulas in B18 and C18 copied down.


Excel 2010 32 bit
ABC
1Look_Up_Value
2Khawar
3List_1List_2
4KhawarTahami
5KhawarIqbal
6KhawarImran
7KhawarZain
8KhawarTahami
9KhawarIqbal
10ZainKhawar
11TahamiKhawar
12IqbalKhawar
13TahamiKhawar
14ImranKhawar
15ZainKhawar
16
17ResultResult Count
18Tahami4
19Iqbal3
20Imran2
21Zain3
22
List & Count
Cell Formulas
RangeFormula
B18=GetName(B$4:C$15,$A$2,ROWS(B$18:B18))
C18=IF(B18="","",COUNTIFS(B$4:B$15,A$2,C$4:C$15,B18)+COUNTIFS(B$4:B$15,B18,C$4:C$15,A$2))
 
Upvote 0
Re: Lookup one vaule in two lists and identify corresponding values

Hi Peter_SSs,

Your solution worked Sir.

Thanks.
 
Upvote 0

Forum statistics

Threads
1,215,339
Messages
6,124,381
Members
449,155
Latest member
ravioli44

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