码迷,mamicode.com
首页 > 其他好文 > 详细

Excel宏开发之合并单元格

时间:2019-09-09 16:22:35      阅读:254      评论:0      收藏:0      [点我收藏+]

标签:got   col   alignment   单元格   visible   cat   range   color   ext   

合并单元格

Sub 宏1()
‘
‘ 宏1 宏
‘
‘ 快捷键: Ctrl+q    Application.Goto Reference:="宏1"
    Application.VBE.MainWindow.Visible = True
    
    Application.DisplayAlerts = False
    
    For i = [A65536].End(3).Row To 2 Step -1
        If Cells(i - 1, 1) = Cells(i, 1) Then
            Cells(i - 1, 1).HorizontalAlignment = xlCenter
            Cells(i - 1, 1).VerticalAlignment = xlCenter
            Range(Cells(i - 1, 1), Cells(i, 1)).Merge
        End If
    Next
    
    For i = [B65536].End(3).Row To 2 Step -1
        If Cells(i - 1, 2) = Cells(i, 2) Then
            Cells(i - 1, 2).HorizontalAlignment = xlCenter
            Cells(i - 1, 2).VerticalAlignment = xlCenter
            Range(Cells(i - 1, 2), Cells(i, 2)).Merge
        End If
    Next
    
     For i = [C65536].End(3).Row To 2 Step -1
        If Cells(i - 1, 3) = Cells(i, 3) Then
            If Cells(i - 1, 2) = Cells(i, 2) Then
            Cells(i - 1, 3).HorizontalAlignment = xlCenter
            Cells(i - 1, 3).VerticalAlignment = xlCenter
            Range(Cells(i - 1, 3), Cells(i, 3)).Merge
            End If
        End If
    Next

    Application.DisplayAlerts = True
    
    Application.VBE.MainWindow.Visible = False
End Sub

 

Excel宏开发之合并单元格

标签:got   col   alignment   单元格   visible   cat   range   color   ext   

原文地址:https://www.cnblogs.com/miaosj/p/11492352.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!