Created
February 21, 2017 14:17
-
-
Save ndthanh/03be0caaed94b0ae71a510e8d097c94d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sub MergeSameCell() | |
Dim Rng As Range, xCell As Range | |
Dim xRows As Integer | |
xTitleId = "HocExcel.Online" | |
Set WorkRng = Application.Selection | |
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8) | |
Application.ScreenUpdating = False | |
Application.DisplayAlerts = False | |
xRows = WorkRng.Rows.Count | |
For Each Rng In WorkRng.Columns | |
For i = 1 To xRows - 1 | |
For j = i + 1 To xRows | |
If Rng.Cells(i, 1).Value <> Rng.Cells(j, 1).Value Then | |
Exit For | |
End If | |
Next | |
WorkRng.Parent.Range(Rng.Cells(i, 1), Rng.Cells(j - 1, 1)).Merge | |
i = j - 1 | |
Next | |
Next | |
Application.DisplayAlerts = True | |
Application.ScreenUpdating = True | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment