EXCEL – macros根据单元格值有条件地合并行

如果当前行的Col C的内容是空的,我在VBAmacros后合并当前行的内容和前一行的内容


input
 Col A |  Col B |  Col C 
 text1A |  text1B |  1
 text2A |  text2B | 
 text3A |  text3B | 
 text4A |  text4B |  2
 text5A |  text5B | 

产量
 Col A |  Col B |  Col C 
 text1A text2A text3A |  text1B text2B test3B |  1
 text4A text5A |  text4B text5B |  2

也有类似的问题,但是我对VBA的了解太过于基本,不适用于这个特定案例的回应。 谢谢!

我想这个问题会帮助你find你需要的解决scheme。你的问题几乎是一个重复的问题。

Sub mergeCategoryValues() Dim lngRow As Long With ActiveSheet lngRow = .Cells(65536, 1).End(xlUp).Row .Cells(1).CurrentRegion.Sort key1:=.Cells(1), Header:=xlYes Do If .Cells(lngRow, 1) = .Cells(lngRow - 1, 1) Then .Cells(lngRow - 1, 3) = .Cells(lngRow - 1, 3) & "; " & .Cells(lngRow, 3) .Rows(lngRow).Delete End If lngRow = lngRow - 1 Loop Until lngRow = 1 End With End Sub 

这个代码为我工作。答案是张贴在这里的问题