Excel合并相似的行和总和单元格

合并相似的行(只有订单号字母不同于a4; a6; a8和生产数量)和总和(生产数量e4; e6; e8)单元格的最佳方法是什么? 这就是excel表格的外观 在这里输入图像说明

澄清:这是我正在寻找的输出 在这里输入图像说明

第4行,第6行和第8行除了订单栏(6和8加上一个字母)和生产栏(不同的生产数量)之外是相同的。 第4,6,8行合并并产生数量。 行6,8被隐藏或删除。

这是一个可以解决你的问题的例子:

Sub test() i = 1 produced = 0 While Cells(i, 1) <> "" Or Cells(i + 1, 1) <> "" If Cells(i, 1) <> "" Then produced = Cells(i, 5) j = 1 'second loop to add up every line with the same order, then suppress the lines While Cells(j, 1) <> "" Or Cells(j + 1, 1) <> "" If Left(Cells(j, 1), 7) = Left(Cells(i, 1), 7) And i <> j Then produced = produced + Cells(j, 5) Cells(j, 5).EntireRow.Select Selection.Delete Shift:=xlUp j = j - 1 End If j = j + 1 Wend End If i = i + 1 Wend 

好的,这里是修改的@Bitoubi代码,帮助我:

 Sub RemoveSplitOrders() i = 1 produced = 0 While Cells(i, 1) <> "" Or Cells(i + 1, 1) <> "" If Cells(i, 1) <> "" Then produced = Cells(i, 20) j = 1 'second loop to add up every line with the same order, then suppress the lines While Cells(j, 1) <> "" Or Cells(j + 1, 1) <> "" If Left(Cells(j, 1), 8) = Left(Cells(i, 1), 8) Or Left(Cells(j, 1), 9) = Left(Cells(i, 1), 9) Then If Cells(j, 2) = Cells(i, 2) And i <> j Then produced = produced + Cells(j, 20) Cells(i, 20).Value = produced Range(Cells(j, 20), Cells(j + 1, 20)).EntireRow.Delete Shift:=xlUp j = j - 1 End If End If j = j + 1 Wend End If i = i + 1 Wend End Sub