Created
March 31, 2017 06:29
-
-
Save ndthanh/fc25033dc5f6d40b7a9b2385358e6bd4 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() | |
'https://www.hocexcel.online | |
Dim Rng As Range, xCell As Range | |
Dim xRows As Integer | |
xTitleId = "Hoc Excel 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