1. Sub 合并单元格()
    2. Dim Rng As Range, PreviousRng As Range, TargetRng As Range
    3. If TypeName(Selection) <> "Range" Then Exit Sub
    4. If Selection.Columns.Count > 1 Then MsgBox "请选择一列区域": Exit Sub
    5. Set TargetRng = Intersect(ActiveSheet.UsedRange, Selection)
    6. Set PreviousRng = TargetRng(1)
    7. Application.DisplayAlerts = False
    8. For Each Rng In TargetRng.Offset(1, 0)
    9. If Rng <> Rng.Offset(-1, 0) Then
    10. Range(PreviousRng, Rng.Offset(-1, 0)).Merge
    11. Set PreviousRng = Rng
    12. End If
    13. Next
    14. Application.DisplayAlerts = True
    15. End Sub
    1. Sub 取消合并单元格()
    2. Dim Rng As Range
    3. Application.FindFormat.Clear
    4. Application.FindFormat.MergeCells = True
    5. If TypeName(Selection) <> "Range" Then Exit Sub
    6. If Selection.MergeCells = False Then Exit Sub
    7. Do
    8. Set Rng = Selection.Find("", , , , , , , , True)
    9. With Rng.MergeArea
    10. .UnMerge
    11. .Value = Rng.Value
    12. End With
    13. Set Rng = Selection.Find("", Rng, , , , , , , True)
    14. If Rng Is Nothing Then Exit Do
    15. Loop
    16. End Sub