Private Sub MergeSelectonCellsVerticalByContent()
Dim a%, b%
Dim n As Long
n = Selection.Rows.Count '选中区域的行数
a = Selection.Row '选中区域的起始行
b = Selection.Column '选中区域的起始列
Application.DisplayAlerts = False '禁用警告提示
For i = a + n - 1 To a + 1 Step -1 '从选中区域的最后一个单元格向上循环
If Cells(i - 1, b) = Cells(i, b) Then '若当前单元格内容与上一个单元格内容相同,则
Range(Cells(i - 1, b), Cells(i, b)).Merge '合并当前单元格和上一个单元格
End If
Next
Application.DisplayAlerts = True '恢复警告提示
End Sub