简体   繁体   中英

How do you make a cell return one of a list of values based on a comparison of two other cells in Google Sheets?

类型图表

I have made a spreadsheet with type matchups for Pokemon. In A1 there is a dropdown of the attacking type and in B1 there is the defending type. I would like for C1 to spit out the type of effectiveness of the matchup. My original thought was to have C1 compare A1 to the cell in column B that matched its value, for example, if A1="Bug" C1 would find B3, and then C1 would compare B1 to the cell in row 2 that matched its value, for example, if B1="Dark" C1 would find D2. Then I would have C1 return the value from D3, the value you find from looking at column D and row 3.

How can I do this in sheets?

try:

=INDIRECT(ADDRESS(MATCH(A1, B2:B, 0)+1, MATCH(B1, 2:2, 0), 4))

0

You have a matrix of values with descriptors for each row and column. You want to name a descriptor for each of the horizontal and vertical axes, and return the value at the intersection of the row and column.

The following formula (entered at Cell C3) will return the value.

=index($C$3:$G$7,(match(A1,$B$3:$B$7,0)),(match(B1,$C$2:$G$2,0)))

Note: my test data spanned "$C$3:$G$7"; you will need to expand this for your data.

The answer uses both match and index :

  • match(A1,$B$3:$B$7,0) : this looks up the Attacking Type (in cell A1) and then returns the row number for a match in column B
  • match(B1,$C$2:$G$2,0) : this looks up the Defending Type (in cell B1) and then returns the Column number for a match in Row 2
  • INDEX : the syntax of index is "INDEX(reference, [row], [column])". The row and column have been supplied by the match statements. The "reference" is the matrix of data. The result is the value at the intersection of the row and column.

In this case, Attacking Type="BUG" and Defending Type = "Dark" will yield an outcome of "2x."

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