简体   繁体   中英

Excel: Create Custom Sheet 2 Based on Data in Sheet 1

I have two sheets in a spreadsheet. Each sheet has a first column with common values (however they are not sorted the same and they are not all there in each sheet).

What I'm trying to do, if possible, is put a formula in sheet 2, where, if column 1 is a match for sheet 1, copies selective data from certain columns in that same row in sheet 1, to certain columns in sheet 2.

Example:

Sheet 1 has a heading setup and sample data row like this:

Title | Day of Week | First | Last

Supervisor | Wednesday | Mike | Jones

Sheet 2 has a heading setup and sample data row like this:

Title | Surname | Weekday

Supervisor | (empty cell) | (empty cell)

After running the mystery formula I'm looking for, placed in the 2 empty cells above, sheet 2 should match on the Supervisor key in sheet 1 and copy in data I have specified into each column, such as:

Title | Surname | Weekday

Supervisor | Jones | Wednesday

(In this case I have told it to map the "day of week" column to weekday, and map the "last" column to "surname").

I hope this is easy/possible??? Help???

VBA is not necessary. You can use a simple VLOOKUP:

=VLOOKUP(cell to look-up, range where you want to look up the values (first column *must* contain the keys to look-up) including all columns that you want to retrieve, the position of the column to be retrieved relative to the first column specified in argument 2, 0 (specifies you want an exact match))

For example:

=VLOOKUP(A1, Sheet1!$A$1:$D$150, 2, 0) ' Retrieves the 2nd column matching criteria in A1

Please notice, however, that you need your keys to be unique. Matching information based on the title seems a bit odd since it is likely there will be more than one person assigned to a certain role. For example, there may be more than 1 supervisor.

Use INDEX and MATCH (better than VLOOKUP).

I suggest renaming your headers so they match on both sheet.

Sheet 1 should be :

Title | Weekday | First Name | Surname

In sheet 2, cell B2 type in

=INDEX(Sheet1!$A:$D,match($A2,Sheet1!$A:$A,0),match(B$2,Sheet1!$1:$1,0))

You can drag and drop it in column C as well, it will work since you are using two MATCH functions with the cells properly anchored.

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