excel中有没有办法让符合条件的单元格自动合并?

如图所示,如何让5上面的空单元格与有5的这个单元格一次自动合并合并后像这样的,或者是录制宏什么的,有没有办法一次可以搞定,数据量过大,一个个合并太耗时了!

按ALT+F11,然后在左边点鼠标右键插入一个模块,输入以下内容后再按F5。
如有不明白可发邮件到[email protected]

Sub M1()
Dim EndRow, Arr1, Arr2(), MyUnion
EndRow = Cells(65536, 1).End(xlUp).Row
Arr1 = Range(Cells(2, 1), Cells(EndRow, 1))
ReDim Arr2(1 To UBound(Arr1, 1), 1 To 1)
Cells(2, "C").Resize(UBound(Arr1, 1), 1).Clear
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
x = 1
For i = 2 To UBound(Arr1, 1)
If Arr1(i, 1) = Arr1(i - 1, 1) Then
x = x + 1
If x = 3 Then
Arr2(i, 1) = 5
x = 0
End If
Else
Arr2(i - 1, 1) = 5
x = 1
End If
Next
Cells(2, "C").Resize(UBound(Arr2, 1), 1) = Arr2
Arr1 = Range(Cells(1, "C"), Cells(EndRow, "C"))
Set MyUnion = Cells(2, "C")
For i = 2 To EndRow
If Arr1(i, 1) = "" Then
Set MyUnion = Union(MyUnion, Cells(i, "C"))
Else
Set MyUnion = Union(MyUnion, Cells(i, "C"))
MyUnion.Merge
Set MyUnion = Cells(i + 1, "C")
End If
Next
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub
温馨提示:答案为网友推荐,仅供参考
第1个回答  2012-12-14
第2个回答  2021-01-16

合并excel机器人可以自动将同一文件夹中的excel按自定义行数进行合并。合并excel:https://store.uibot.com.cn/robots/detail/918.html

相似回答