elsg
12-21-2013, 03:06 PM
I'm trying to have a unique code to delete duplicates.
unfortunately what I got was just having two routines to delete duplicate rows.
I try make something based link above, but i can't it
http://www.vbaexpress.com/forum/showthread.php?10600-Solved-Delete-Duplicate-Rows-based-on-multiple-columns
Option Explicit
Sub DeleteDups()
Dim ws1 As Worksheet
Dim lrws1 As Long, i As Long
Call TipFormula '<- secondth code
Set ws1 = Sheets("Plan3")
Application.ScreenUpdating = 0
lrws1 = ws1.Cells(Rows.Count, "A").End(xlUp).Row
For i = 2 To lrws1
ws1.UsedRange.AutoFilter Field:=8, Criteria1:="Duplicate"
ws1.UsedRange.Offset(1, 0).SpecialCells(xlCellTypeVisible).EntireRow.Delete
Next i
ws1.AutoFilterMode = False
Application.ScreenUpdating = 1
End Sub
Secondth code
Sub TipFormula()
Dim lr As Long
'Application.ScreenUpdating = False
Const sFormula1 As String = "=IF(SUM(COUNTIF($B2:$G2,B2)>1,COUNTIF($B2:$G2,C2)>1,COUNTIF($B2:$G2,D2)>1,COUNTIF($B2:$G2,E2)>1,COUNTIF($B2:$G2,F2)>1,COUNTIF($B2:$G2,G2)>1),""Duplicate"","""")"
With Sheets("Plan3")
lr = .Cells(.Rows.Count, "A").End(xlUp).Row + 1
.Range("H2").FormulaArray = sFormula1
.Range("H2").AutoFill .Range("H2").Resize(lr - 1)
.Range("H2").Resize(lr, 8).Value = .Range("H2").Resize(lr, 8).Value
End With
'Application.ScreenUpdating = True
End S
unfortunately what I got was just having two routines to delete duplicate rows.
I try make something based link above, but i can't it
http://www.vbaexpress.com/forum/showthread.php?10600-Solved-Delete-Duplicate-Rows-based-on-multiple-columns
Option Explicit
Sub DeleteDups()
Dim ws1 As Worksheet
Dim lrws1 As Long, i As Long
Call TipFormula '<- secondth code
Set ws1 = Sheets("Plan3")
Application.ScreenUpdating = 0
lrws1 = ws1.Cells(Rows.Count, "A").End(xlUp).Row
For i = 2 To lrws1
ws1.UsedRange.AutoFilter Field:=8, Criteria1:="Duplicate"
ws1.UsedRange.Offset(1, 0).SpecialCells(xlCellTypeVisible).EntireRow.Delete
Next i
ws1.AutoFilterMode = False
Application.ScreenUpdating = 1
End Sub
Secondth code
Sub TipFormula()
Dim lr As Long
'Application.ScreenUpdating = False
Const sFormula1 As String = "=IF(SUM(COUNTIF($B2:$G2,B2)>1,COUNTIF($B2:$G2,C2)>1,COUNTIF($B2:$G2,D2)>1,COUNTIF($B2:$G2,E2)>1,COUNTIF($B2:$G2,F2)>1,COUNTIF($B2:$G2,G2)>1),""Duplicate"","""")"
With Sheets("Plan3")
lr = .Cells(.Rows.Count, "A").End(xlUp).Row + 1
.Range("H2").FormulaArray = sFormula1
.Range("H2").AutoFill .Range("H2").Resize(lr - 1)
.Range("H2").Resize(lr, 8).Value = .Range("H2").Resize(lr, 8).Value
End With
'Application.ScreenUpdating = True
End S