VAB로 엑셀 셀 합치기, 초간단 코드

엑셀 시트에서 셀을 선택하고 실행하면 셀이 자동으로 합처지는 초간단 VB 코드입니다.

 

 

Sub testCellMerge()
    Dim rStart As Range
    Dim rend As Range
    Dim index As Integer

    Application.DisplayAlerts = False
    Set rStart = Selection.Cells(1)

    For index = 1 To Selection.Cells.Count
        If Selection.Cells(index) <> Selection.Cells(index + 1) Then
            Set rend = Selection.Cells(index)
            Range(rStart, rend).Merge
            Set rStart = Selection.Cells(index + 1)
        End If
    Next

    Application.DisplayAlerts = True
    
End Sub