Tôi có lấy trên webketoan hay là giaiphapexcel (quên mất rồi) có 1 thủ tục như sau:
Chọn vùng cần lấy danh mục (mã HH...) và thực hiện macro trên, nhưng hôm nay làm lại để chỉ cho bạn thì nó báo lỗi.(ở dòng tô đậm và I). Vậy các anh chị chỉ giúp cho hòan chỉnh, nếu có thể thì giải thích tại sao. Cám ơn nhiều.
Chọn vùng cần lấy danh mục (mã HH...) và thực hiện macro trên, nhưng hôm nay làm lại để chỉ cho bạn thì nó báo lỗi.(ở dòng tô đậm và I). Vậy các anh chị chỉ giúp cho hòan chỉnh, nếu có thể thì giải thích tại sao. Cám ơn nhiều.
Mã:
[B]Public Sub Delete_Record()[/B]
Dim rngData As Range
Dim i As Integer, j As Integer
ActiveSheet.Copy Before:=ActiveSheet
Set rngData = Selection
For i = 1 To rngData.Rows.Count - 1
For j = i + 1 To rngData.Rows.Count
If rngData.Cells(j, 1) = rngData.Cells(i, 1) And rngData.Cells(j, 2) = _
rngData.Cells(i, 2) And rngData.Cells(j, 3) = rngData.Cells(i, 3) Then
rngData.Cells(j, 1) = "": rngData.Cells(j, 2) = ""
rngData.Cells(j, 3) = ""
[COLOR="Blue"]'Range(rngData.Cells(j, 1), rngData.Cells(j, 3)).Select[/COLOR]
[COLOR="blue"]'Selection.Delete Shift:=xlUp[/COLOR]
End If
Next j, i
[I][B] Selection.Sort Key1:=Range(Selection.Cells(1, 1).Address), Order1:=xlAscending, _
Key2:=Range(Selection.Cells(1, 2).Address), Order2:=xlAscending, _
Key3:=Range(Selection.Cells(1, 3).Address), Order3:=xlAscending, _
Header:=xlNo, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, DataOption3:=xlSortNormal[/B][/I]
[B]End Sub[/B]
Chỉnh sửa lần cuối bởi điều hành viên: