PDA

View Full Version : Sleeper: Import, Skip Duplicate Records



sal21
09-28-2004, 08:45 AM
This sheet import a file.
In column G are the unique value
my problem, during the import file, skip the rekord if this is already imported
(for example if i impot the same file twice)

HalfAce
09-28-2004, 02:04 PM
Hi Sal,



Here's a routine that should delete the entire row(s) of any exact duplicates within the used range. It won't prevent the data from being imported twice, but should clean it up after the fact if it happens.


Sub DeleteDuplicateRows()
Dim iRow As Long
Dim jRow As Long
Dim iCol As Integer
Dim LastRow As Long
Dim FirstRow As Long
Dim FirstCol As Integer
Dim LastCol As Integer
Dim DelCount As Long
Dim DupFound As Boolean
DelCount = 0
Range("B11").CurrentRegion.Select '(Selects the range)
FirstRow = Selection.Row
LastRow = FirstRow + Selection.Rows.Count - 1
FirstCol = Selection.Column
LastCol = FirstCol + Selection.Columns.Count - 1
For iRow = FirstRow To LastRow - 1
For jRow = iRow + 1 To LastRow
DupFound = True
For iCol = FirstCol To LastCol
DupFound = DupFound And (Cells(jRow, iCol) = Cells(iRow, iCol))
If Not DupFound Then Exit For
Next iCol
If DupFound Then
Rows(jRow).Delete
LastRow = LastRow - 1
DelCount = DelCount + 1
End If
Next jRow
Next iRow
[A1].Select
End Sub

Just change the reference from B11 to the Top / Left cell of you range of interest.

Hope it helps,

Dan

Anne Troy
09-28-2004, 10:11 PM
Sal
1 help 1 pizza
2 help 1 pizza 1 caff?
3 help 1 pizza 1 caff? 1 mozzarella

Forget it, Sal. I want the pasta!!
How do I get the spaghetti!!??

sal21
09-29-2004, 12:30 AM
Ok! ... for the spaghetti, i adjust my signature...

Anne Troy
09-29-2004, 12:33 AM
LOL!! Yes. Spaghetti will be safer now, I think. I tell you, I ate pizza, and it is true--not a joke! Hee hee.

sal21
09-29-2004, 12:57 AM
Tks HalfAce, but for me is important during the import of file....