300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > Excel Vba 纵向合并相同内容的连续单元格

Excel Vba 纵向合并相同内容的连续单元格

时间:2021-08-23 00:08:25

相关推荐

Excel Vba 纵向合并相同内容的连续单元格

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

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。