zoukankan      html  css  js  c++  java
  • Excel宏开发之合并单元格

    合并单元格

    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
                 flag = True
                 If (Cells(i, 1) <> "") Then
                    flag = False
                 End If
                 If flag Then
                    Cells(i - 1, 2).HorizontalAlignment = xlCenter
                    Cells(i - 1, 2).VerticalAlignment = xlCenter
                    Range(Cells(i - 1, 2), Cells(i, 2)).Merge
                 End If
            End If
        Next
        
         For i = [C65536].End(3).Row To 2 Step -1
            If Cells(i - 1, 3) = Cells(i, 3) Then
                 flag = True
                 If (Cells(i, 2) <> "") Then
                    flag = False
                 End If
                 If flag 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
  • 相关阅读:
    SpringMVC框架
    Spring框架
    Test_Shop项目开发练习
    MyBatis动态传参
    存储过程
    游标和触发器
    远程连接Linux系统管理
    安装Linux虚拟机
    request_html模块(下)
    request_html模块(上)
  • 原文地址:https://www.cnblogs.com/miaosj/p/11492352.html
Copyright © 2011-2022 走看看