1、启用宏
2、Alt F11
代码如下(去除中文):
Sub CancelMergeCells() Dim r As Integer,MergeStr As String,MergeCot As Integer,i As Integer Dim rng As Range On Error Resume Next 选择需要合并的列,由用户进行制定,并限定值 Set rng = Application.InputBox("请输入需要合并的列", "区域选择", , , , , , 8) 将用户指定的单元列取得行号 k = rng.Column With Sheet1 取得最大循环数 r = .Cells(.Rows.Count, 1).End(xlUp).Row For i = 2 To r 将合并单元格赋值给到变量 MergeStr = .Cells(i, k).Value 计算合并单元格区域的大小 MergeCot = .Cells(i, k).MergeArea.Count 取消合并单元格 .Cells(i, k).UnMerge 将取消的单元格进行赋值填充 .Range(.Cells(i, k), .Cells(i + MergeCot - 1, k)).Value = MergeStr 循环的步长进行累加,减少循环的次数 i = i + MergeCot - 1 Next 添加边框线,数据美化 .Range("A1:C" & r).Borders.LineStyle = xlContinuous End With End Sub
3、添加按钮指定宏
4、点击按钮选中列(不需输入直接选中列即可)