简体   繁体   中英

Excel | Searching table in different sheet and bringing value from column in that row

I am trying to lookup a table in one of my sheets. my table consists of three columns and an unlimited amount of rows.

My table can be seen here:

在此输入图像描述

In my second sheet I wish to write a formula which searches all rows in the table and looks for an exact match in column A and column B, this means it must find the row where column a has a value of "jan" and in that same row the second column must have value "y". Should it find this match, it should return the value of column C.

I tried researching hlookup but that is for horizontal tables so i dont believe this would work. I looked into Vlookups also but that only allows one criteria search instead of looking for two matches.

Can anyone shed some light here please?

You can use index and match with multiple criteria

=INDEX($A$1:$C$1000, MATCH("Jan"&"y", $A$1:$A$1000&$B$1:$B$1000, 0),3)

press CTRL + SHIFT + ENTER when entering this formula.

The INDEX function has the syntax

INDEX(array, row_num_in_array, [column_num_in_array])

And MATCH returns in the index location of a logic match

MATCH(lookup_value, lookup_array, [match_type])

Combining the two is a flexible technique, and surprisingly powerful -- the logic in a match lookup_value can be a complex condition.

SIMPLEST CODE

Operate on the whole column

INDEX(C:C, MATCH("Jan"&"y", A:A&B:B, 0), 1)

nb./ A:A is excel code for "all of column A". You can instead use:

RESTRICTED CODE

Operates on a subset of the sheet.

INDEX($C$2:$C$1000, MATCH("Jan"&"y", $A$2:$A$1000&$B$2:$B$1000, 0), 1)

Note that you MUST use identical row length arrays (eg. rows 2:1000) or the formula will not work. MATCH only knows how many rows into its lookup_array it got, you need to ensure its rows match those in INDEX 's array

PS. apologies this is close to the previous answer, but the details were too long for a comment.

PPS. I missed the clarifications to the first answer. That will work, but there is no need to use all three columns as the array in the INDEX function. You are only returning data from column C after all.

Convert the range to a table (ctrl-t) and then use SUMIFS to search the table based on two criteria

=SUMIFS(Table1[Alteration],Table1[Month],"Jan",Table1[Products],"y")

This is saying "give me [Alteration] where [Month] = "Jan" and [Products] = 'y'...this returns 364.

You can point the criteria at separate cells containing your criteria.

Be aware that if there is more than one row with identical data (ie more than one row with both 'Jan' and 'y'), column C will be summed together.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM