thang_nguyen1
Thành viên hoạt động



- Tham gia
- 6/10/16
- Bài viết
- 136
- Được thích
- 8
Mọi người hỗ trợ code xóa dữ liệu trùng tương tự với code xóa dòng trống. Mình không rành về VBA nên các bạn hỗ trợ và tư vấn giúp mình.
Mã:
Sub RemoveBlankRow()
'Chon tat ca cac dong trong
Dim rRow As Range
Dim rSelect As Range
Dim rSelection As Range
'Kiem tra pham vi du lieu da duoc chon
If TypeName(Selection) <> "Range" Then
MsgBox "Please select a range first.", vbOKOnly, "Select Blank Rows Macro"
Exit Sub
End If
'Kiem tra cac o tinh da duoc chon
If Selection.Cells.Count = 1 Then
Set rSelection = ActiveSheet.UsedRange
Else
Set rSelection = Selection
End If
'Lap lai tung dong de them o tinh trong vao rSelect range
For Each rRow In rSelection.Rows
If WorksheetFunction.CountA(rRow) = 0 Then
If rSelect Is Nothing Then
Set rSelect = rRow
Else
Set rSelect = Union(rSelect, rRow)
End If
End If
Next rRow
'Chon cac o tinh trong
If rSelect Is Nothing Then
MsgBox "No blank rows were found.", vbOKOnly, "Select Blank Rows Macro"
Exit Sub
Else
rSelect.Select
'Luu y: Ban khong the hoan tac xoa dong trong nay
rSelect.Rows.Delete Shift:=xlShiftUp
End If
End Sub