Skip to content

Instantly share code, notes, and snippets.

@ndthanh
Created March 31, 2017 06:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ndthanh/fc25033dc5f6d40b7a9b2385358e6bd4 to your computer and use it in GitHub Desktop.
Save ndthanh/fc25033dc5f6d40b7a9b2385358e6bd4 to your computer and use it in GitHub Desktop.
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