简体   繁体   English

如果在 MS EXCEL 中匹配,则将具有重复项的列值替换为另一列

[英]replace a column value having duplicates with another column if matched in MS EXCEL

I have a Table, say TABLE-1 with 4 columns.我有一个表,比如说有 4 列的 TABLE-1。 Columns are (ID, NAME, GROUP_NAME, IS_APPROVER), ID is not the primary key.列是 (ID, NAME, GROUP_NAME, IS_APPROVER),ID 不是主键。 There are many rows with same ID.有许多行具有相同的 ID。 Now I got a new Table, say TABLE-2 with Columns, (NEW_ID, OLD_IDs), in this table (TABLE-2), OLD_ID is the primary Key.现在我得到了一个新表,比如带有列的 TABLE-2,(NEW_ID,OLD_IDs),在这个表(TABLE-2)中,OLD_ID 是主键。 I have to replace all the values of IDs in TABLE-1, with the NEW_ID (in TABLE-2) values compared using OLD_ID (in TABLE-2).我必须将 TABLE-1 中的所有 ID 值替换为 NEW_ID(在 TABLE-2 中)值,并使用 OLD_ID(在 TABLE-2 中)进行比较。 How can I do this?我怎样才能做到这一点?

Assuming your tables look like the below:假设您的表格如下所示:

表格示例

You should just be able to use a combination of INDEX and MATCH to get your desired results:您应该能够结合使用 INDEX 和 MATCH 来获得所需的结果:

=INDEX(TABLE-2[NEW_ID],(MATCH(TABLE-1[@ID],TABLE-2[OLD_IDs],0)))

If your data is not actually in tables but in ranges the general formula is:如果您的数据实际上不在表格中,而是在范围内,则一般公式为:

=INDEX(ColumnFromWhichValueShouldBeReturned, (MATCH(LookupValue, ColumnAgainstWhichToLookup, 0)))

EDIT following further info from OP:编辑以下来自 OP 的更多信息:

If not all the ID's are matched in TABLE-2 you can use the following:如果不是所有 ID 都在 TABLE-2 中匹配,您可以使用以下内容:

=IFERROR(INDEX(TABLE-2[NEW_ID],(MATCH(TABLE-1[@ID],TABLE-2[OLD_IDs],0))), Table1[@ID])

In practice you can see this working below:在实践中,你可以在下面看到这个工作:

显示在实践中工作的公式

You could potentially use VLOOKUP to make it a little easier.您可以潜在地使用 VLOOKUP 使其更容易一些。在此处输入图片说明

I added a new column to the first table and the formula for that column is simply我在第一个表中添加了一个新列,该列的公式很简单

=VLOOKUP([@ID], Table2[#All], 2)

This is the solution..这是解决方案..

Ref: https://www.ablebits.com/office-addins-blog/2014/08/13/excel-index-match-function-vlookup/参考: https : //www.ablebits.com/office-addins-blog/2014/08/13/excel-index-match-function-vlookup/

=INDEX(Table_2[NewIDs],MATCH(Table_1[@ID],Table_2[Old_ID],0)) Ex: =INDEX($K$2:$K$253,MATCH(B2,$J$2:$J$253,0)) =INDEX(Table_2[NewIDs],MATCH(Table_1[@ID],Table_2[Old_ID],0​​)) 例如:=INDEX($K$2:$K$253,MATCH(B2,$J$2:$J$253,0) ))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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