简体   繁体   中英

In Excel, how to populate cell based on match between row in one sheet and column in another sheet

I have one Excel worksheet containing a list of fuel types for each state, and I need to populate each row with a fuel price rate code from another sheet. The data is laid out like this:

Sheet 1:
State | Fuel Type  | Rate Code
"AL"    "DIESEL"     [blank]
"AL"    "GASOLINE"   [blank]
"AZ"    "DIESEL"     [blank]
"AZ"    "GASOLINE"   [blank]

Sheet 2:
State | Diesel | Gasoline
"AL"    "084"    "085"
"AZ"    "081"    "082"

What I would like to do is say, "If I'm looking at the row in Sheet 1 that contains "AL" and "DIESEL", go to Sheet 2 and find the rate code in the Diesel column on the AL row, and put it in the Rate Code column in Sheet 1." (In this case the value I'm looking for would be "084".)

In reality the file contains 12 fuel types and all US and Canadian jurisdictions so it's not practical to manually do this.

I'm familiar with functions like VLOOKUP but nothing seems to work and I can't wrap my head around this. Is there a way to do this with one or more functions or does this look more like a job for VBA or other solution? Any help is appreciated!

You want INDEX/MATCH/MATCH:

=INDEX(Sheet2!$A:$C,MATCH(A2,Sheet2!$A:$A,0),MATCH(B2,Sheet2!$1:$1,0))

在此处输入图片说明


Sheet2 for reference:

在此处输入图片说明

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