vba 如何根据条件合并Excel中的不同行?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28615355/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-12 06:17:41  来源:igfitidea点击:

How to merge different rows in Excel based on a condition?

excelexcel-vbavba

提问by Sachin B. R.

How do I merge different rows in an Excel sheet into one row without losing any data by testing if the content of one of the column is equal. Also the merged rows should be treated as one single row. For example:

如何通过测试其中一列的内容是否相等,将 Excel 工作表中的不同行合并为一行而不会丢失任何数据。此外,合并的行应视为一行。例如:

  row  Title1   Title2
   1     1        sdf
   2     1        dsf
   3     2        dsf
   4     3        dsaf
   5     3        asd

I want the above Excel sheet to become like so:

我希望上面的 Excel 表变成这样:

  row  Title1   Title2
   1     1        sdf
                  dsf
   2     2        dsf
   3     3        dsaf
                  asd

回答by risail

=IF (Logic_Test, Value_if_True, Value_if_False)so for you it would be something like this in the D column=IF(A1=A2, “=A1&B1&C1” , NA())

=IF (Logic_Test, Value_if_True, Value_if_False)所以对你来说它会是这样的 D column=IF(A1=A2, “=A1&B1&C1” , NA())