miaosj

合并单元格

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

 

分类:

技术点:

相关文章:

  • 2022-02-06
  • 2022-01-24
  • 2021-12-22
  • 2022-12-23
  • 2021-07-25
猜你喜欢
  • 2022-01-20
  • 2021-11-22
  • 2022-01-05
  • 2021-10-30
  • 2021-06-18
相关资源
相似解决方案