Sub MergeCell1()
Dim rngI As Range
Dim rngO As Range
Dim oCol As Integer
On Error GoTo 1
With Application
.ScreenUpdating = False
Set rngI = .InputBox(prompt:="Chon cot chua du lieu de xet: ", Type:=8)
Set rngO = .InputBox(prompt:="Chon cot chua vung de tron o: ", Type:=8)
oCol = rngO.Column - rngI.Column
Set rngI = rngI(1, 1).EntireColumn
Set rngI = rngI.SpecialCells(Type:=xlCellTypeConstants)
For Each rngO In rngI.Areas
rngO.Offset(, oCol).Merge
Next
1:
.ScreenUpdating = True
End With
End Sub
Sub MergeCell2()
Dim rngI As Range
Dim rngO As Range
Dim oCol As Integer
On Error GoTo 1
With Application
.ScreenUpdating = False
Set rngI = .InputBox(prompt:="Chon cot chua du lieu de xet: ", Type:=8)
Set rngO = .InputBox(prompt:="Chon cot chua vung de tron o: ", Type:=8)
oCol = rngO.Column - rngI.Column
Set rngI = rngI(1, 1).EntireColumn
Set rngI = rngI.SpecialCells(Type:=xlCellTypeFormulas)
For Each rngO In rngI.Areas
rngO.Offset(, oCol).Merge
Next
1:
.ScreenUpdating = True
End With
End Sub