excel表格中相邻同样字符的怎样快速合并?
发布网友
发布时间:2022-03-09 05:12
我来回答
共4个回答
热心网友
时间:2022-03-09 06:41
试试这个代码:
Sub 值相同则合并单元格()
Dim first%, last%
Application.ScreenUpdating = False
If Selection.Rows.Count >= 65536 Or Selection.Columns.Count = 256 Then MsgBox "别选整张表啊": Exit Sub
For j = 1 To Selection.Columns.Count
first = 1
For i = 1 To Selection.Rows.Count
If j > 1 Then
If (Selection.Cells(i, j - 1).Value <> Selection.Cells(i + 1, j - 1).Value And (Selection.Cells(i + 1, j - 1).Value <> "" Or Selection.Cells(i + 1, j - 1).MergeCells = False)) Or Selection.Cells(i, j).Value <> Selection.Cells(i + 1, j).Value Then
last = i
' MsgBox Range(Selection.Cells(first, j), Selection.Cells(last, j)).Address & " " & first & " " & last
With Range(Selection.Cells(first, j), Selection.Cells(last, j))
.MergeCells = True
Application.DisplayAlerts = False
End With
first = i + 1
End If
ElseIf Selection.Cells(i, j).Value <> Selection.Cells(i + 1, j).Value Then
last = i
With Range(Selection.Cells(first, j), Selection.Cells(last, j))
.MergeCells = True
Application.DisplayAlerts = False
End With
first = i + 1
End If
Next
Next j
Application.ScreenUpdating = True
End Sub
使用方法:alert+f11,最好是插入一个模块,然后把上述代码拷贝到里面。
然后选中一块区域,单列也行,多列也行,工具,宏,找到这个"值相同则合并单元格",执行
我自己写的(高手莫喷),一直在用,你如果不放心,就复制一张表试一下,希望能够帮助你
热心网友
时间:2022-03-09 07:59
如果同样内容的数量一样,可以先合并1处单元格,再用格式刷
若根本没有规律,靠合并单元格是没有捷径的
热心网友
时间:2022-03-09 09:34
筛选,格式刷
热心网友
时间:2022-03-09 11:25
如果表格基本上一样就,先做好一个,其它全部复制把里面的内容全部清掉再录入内容就可以了.格式刷不好用.只能刷一个.後面又得再去点格式刷了.