Cách gộp nhiều ô thành 1 ô
Nguyễn Dương 06-06-20241. CÁCH GỘP Ô CƠ BẢN
Bạn bôi đen các ô cần gộp, trong thẻ Home chọn Merge & Center => Merge Cells
2. CÁCH GỘP Ô KHÔNG BỊ MẤT DỮ LIỆU
Nếu bạn chưa bật hiện thẻ Developer thì đọc bài viết Cách bật hiện thẻ Developer trong Excel.
Bước 2: Bạn nhập tên vào ô Macro name rồi chọn Create. Ví dụ mình đặt tên là gop
Bước 3: Bạn copy đoạn code dưới đây rồi dán vào giữa Sub và End Sub
Dim Cll As Range, Temp As String
On Error Resume Next
If Selection.MergeCells = False Then
For Each Cll In Selection
If Cll <> "" Then Temp = Temp + Cll.Text + " "
Next Cll
Selection.Merge
Selection.Value = Left(Temp, Len(Temp) - 1)
Else
Selection.UnMerge
End If
Selection.HorizontalAlignment = xlCenter
Selection.VerticalAlignment = xlCenter
Sau đó chọn chạy đoạn code này (F5)
Bước 4: Xuất hiện bảng thông báo, bạn chọn OK
Kết quả ta được như sau
Bài viết liên quan





