简体   繁体   English

根据两列数据生成第三列序号

[英]Generate a 3rd column sequential number based on two columns data

I apologize if the title is misleading, but I have an issue where I need to generate a sequential number in a third column based on comparing data from two different columns. 如果标题令人误解,我深表歉意,但是我遇到一个问题,我需要根据比较两个不同列的数据在第三列中生成一个序列号。

My data looks like this: Before 我的数据是这样的:

The entry with the 1 is the first point, I need to use the value in the 'Back' column to find the same value in the 'Front' Column, then add +1 to the point, so the result looks like: 带有1的条目是第一点,我需要使用“后退”列中的值在“前”列中找到相同的值,然后将+1添加到该点,因此结果如下所示:

After

Because of the naming conventions used, sorting either column by value will not work. 由于使用了命名约定,因此按值对任一列进行排序将不起作用。

Appreciate the help! 感谢帮助!

Assuming you have the initial 1, and your number column is C, front is D, back is E, this would start at row 2: 假设您有首字母1,并且数字列为C,前排为D,后排为E,则此操作将从第2行开始:

=INDEX(C:C,MATCH(INDEX(D:D,MATCH(D2,E:E,0),1),D:D,0),1)+1

Image: http://i.imgur.com/0XfdLrk.png 图片: http : //i.imgur.com/0XfdLrk.png

Did you establish whether your data has duplicates or incomplete sequences? 您确定数据是否重复或不完整?

Here's another formula which should achieve what you want and also doesn't rely on you knowing where the sequence starts. 这是另一个公式,它应该可以实现您想要的功能,并且不依赖于您知道序列从哪里开始。 Every sequence will start with 1. 每个序列都将从1开始。

This formula follows your image layout, putting values into column A with data in columns B and C. Please replace the ranges in the formula for columns A and C to cover all of your data. 该公式将遵循您的图像布局,将值放入B列和C列的A列中。请替换公式中的A列和C列的范围,以覆盖您的所有数据。 (Ideally, you would do this by inserting a table first and then selecting the data rows, which will cause Excel to put in the table column name instead.) (理想情况下,您可以通过先插入表格然后选择数据行来执行此操作,这将导致Excel改为放入表格的列名。)

This is the formula to go into cell A2, assuming you have data in B2:C7 假设您在B2:C7中有数据,这是进入单元格A2的公式

=IF(ISERROR(MATCH(B2,$C$2:$C$7,0)),1,INDEX($A$2:$A$7,MATCH(B2,$C$2:$C$7,0))+1)

Put this formula in D2 and fill down to identify which rows are the ends of sequences: 将此公式放在D2中并向下填充以标识哪些行是序列的结尾:

=ISERROR(MATCH(C2,$B$2:$B$7,0))

Put this formula in E2 and fill down to identify duplicates in the Front column: 将此公式放在E2中,然后填写以在“前”列中标识重复项:

=COUNTIF(B$2:B$7,B2)

You can then fill it right one column to also identify duplicates in Back. 然后,您可以在第一栏中填写它,以在“上一步”中识别重复项。

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

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