Returning a value from a table based on two criteria

povictory

New Member
Joined
May 28, 2015
Messages
41
Hello,

I'm looking for help on a formula to retrieve a value from a table based on two criteria. I'm sure there's probably a fairly easy way to do it, but I'm just struggling to find the best way to do it myself so I'm hoping someone here might be able to help.

I have a list of employees in column A and a list of units in column B. Both employees and units can be repeated in the columns, however each combination of the two is unique.

I also have a look-up table with the employee names listed in the rows and the units listed in the columns. What I'm trying to do is create a formula that will pull a value in the lookup table that matches the employee/unit combo in columns A and B.


ABC
1Employee1Unit1Value from table that matches criteria in column A and B
2Employee1Unit2
3Employee1Unit3
4Employee1Unit4
5Employee2Unit10
6Employee2Unit11
7Employee3Unit5
8Employee3Unit6
9Employee3Unit7
10Employee3Unit8
11Employee3Unit9
12Employee3Unit10

<tbody>
</tbody>

Lookup table:
ABCDEFGHIJK
1Unit1Unit2Unit3Unit4Unit5Unit6Unit7Unit8Unit9Unit10
2Employee15,00010,0005,00010,000
3Employee25,000
4Employee35,0005,00010,00015,0009,0004,000
5Employee46,000
6Employee53,000
7Employee67,000
8Employee7
9Employee817,000
10Employee94,0005,000
11Employee1015,000
12Employee112,000

<tbody>
</tbody>

Any help is GREATLY appreciated!!

Thanks!
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Try adapting this, copied down.

Excel Workbook
ABCDEFGHIJKLMNO
1Unit1Unit2Unit3Unit4Unit5Unit6Unit7Unit8Unit9Unit10
2Employee1Unit15000Employee15,00010,0005,00010,000
3Employee1Unit210000Employee25,000
4Employee1Unit35000Employee35,0005,00010,00015,0009,0004,000
5Employee1Unit410000Employee46,000
6Employee2Unit105000Employee53,000
7Employee2Unit11#N/AEmployee67,000
8Employee3Unit55000Employee7
9Employee3Unit65000Employee817,000
10Employee3Unit710000Employee94,0005,000
11Employee3Unit815000Employee1015,000
12Employee3Unit99000Employee112,000
13Employee3Unit104000
Lookup Table
 
Upvote 0
Try adapting this, copied down.

Lookup Table

*ABCDEFGHIJKLMNO
1*****Unit1Unit2Unit3Unit4Unit5Unit6Unit7Unit8Unit9Unit10
2Employee1Unit15000*Employee15,00010,0005,00010,000******
3Employee1Unit210000*Employee2*********5,000
4Employee1Unit35000*Employee3****5,0005,00010,00015,0009,0004,000
5Employee1Unit410000*Employee4******6,000***
6Employee2Unit105000*Employee5**3,000*******
7Employee2Unit11#N/A*Employee6****7,000*****
8Employee3Unit55000*Employee7**********
9Employee3Unit65000*Employee8*********17,000
10Employee3Unit710000*Employee9*4,000*******5,000
11Employee3Unit815000*Employee10****15,000*****
12Employee3Unit99000*Employee11*******2,000**
13Employee3Unit104000************

<colgroup><col style="font-weight:bold; width:30px; "><col style="width:84px;"><col style="width:56px;"><col style="width:66px;"><col style="width:53px;"><col style="width:92px;"><col style="width:51px;"><col style="width:58px;"><col style="width:51px;"><col style="width:58px;"><col style="width:58px;"><col style="width:51px;"><col style="width:58px;"><col style="width:58px;"><col style="width:51px;"><col style="width:58px;"></colgroup><tbody>
</tbody>

Spreadsheet Formulas
CellFormula
C2=INDEX(F$2:O$12,MATCH(A2,E$2:E$12,0),MATCH(B2,F$1:O$1,0))

<tbody>
</tbody>

<tbody>
</tbody>


Excel tables to the web >> Excel Jeanie HTML 4



Hi Peter,

I'm fairly new to excel and vba. And I'm wondering what if I have done this using vba?
for example:

Code:
Sub findthem()


    Dim i As Integer
    Dim employN, employU As String
    Dim rowT, colT As Long
    
    For i = 2 To 13
        employN = Range("A" & i).Value
        employU = Range("B" & i).Value
        rowT = Columns(5).Find(what:=employN).Row
        colT = Rows(1).Find(what:=employU).Column
        
        Range("C" & i).Value = Cells(rowT, colT).Value
        
    Next i


End Sub


Assume the person has a large chart, will it be significantly slower if I were to do it in VBA instead?
Also do you have any books/websites recommendation in learning excel and/or vba? I am from a computer science background trying to get into a bank, and I've seen a lot of jobs requiring vba/excel. Hope you can give me advice. Thanks!
 
Upvote 0
Hi Peter,

I'm fairly new to excel and vba. And I'm wondering what if I have done this using vba?
Well, you can pretty easily test your own code - and perhaps have already done so.
I haven't tested your code but do have some comments.
1. vba could be very fast. There would be faster ways than using Find (twice) but if the data is not too big that probably wouldn't matter & in any case you are getting practice with that method.
2. You may find some issues with your 'Find' lines. vba Find has quite a few parameters and you need to be careful about leaving some of them out as you have done as Excel remembers some of those settings from a previous Find (vba or manual). For example if the previous Find was looking for a partial match, then when you do a Find for "Unit1" in row 1 you would want to ensure it didn't do a partial match and find "Unit10" instead.
3. When declaring variables, if you want to specify the type (good practice) you need to specify each individual variable. For example ..

Dim rowT, colT As Long

.. this is only declaring colT as Long and rowT will be a Variant because you haven't specified. You would need ..

Dim rowT as Long, colT As Long

4. Also on variable declarations, my understanding is that vba converts all Integer types to Long before using them, so you might as well just declare them as Long to start with. Besides, it is shorter to type. ;)
5. I have done virtually all of my vba learning on this site - doing just what you have done. Find a problem, have a go, learn from feedback, keep going. :)
 
Upvote 0
Thank you for pointing out those concerns, I really had no idea about the find function and haha I assumed dim rowT, rowT as long would declare both as long.

Yeah I figure this site is a good idea, since everyone is posting their real life problem. I've already learnt quite a few from you and a few other posts!

Thanks again, you guys are awesome
 
Upvote 0

Forum statistics

Threads
1,215,149
Messages
6,123,311
Members
449,095
Latest member
Chestertim

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