L
Les Stout
Hi all, i have some code that i got from a search and it was apparantly
supplied by Tom Ogilvy. I need to understand it, as i have a lot of
lines and i need to loop down deleteing lines with duplicate numbers in
Column "A" & "D". However if Column "A" number is different and "D" is
the same it must not delete !! Any help would be greatly appreciated..
Sub DeleteDuplicateRows()
Dim RowNdx As Long
Dim ColNum As Integer
Dim rng As Range
ColNum = Selection(1).Column
For RowNdx = Selection(Selection.Cells.Count).Row To _
Selection(1).Row + 1 Step -1
If Cells(RowNdx, ColNum).Value = Cells(RowNdx - 1, ColNum).Value
Then
If rng Is Nothing Then
Set rng = Cells(RowNdx, ColNum)
Else
Set rng = Union(rng, Cells(RowNdx, ColNum))
End If
End If
Next RowNdx
If Not rng Is Nothing Then
rng.EntireRow.Delete
End If
End Sub
Les Stout
*** Sent via Developersdex http://www.developersdex.com ***
supplied by Tom Ogilvy. I need to understand it, as i have a lot of
lines and i need to loop down deleteing lines with duplicate numbers in
Column "A" & "D". However if Column "A" number is different and "D" is
the same it must not delete !! Any help would be greatly appreciated..
Sub DeleteDuplicateRows()
Dim RowNdx As Long
Dim ColNum As Integer
Dim rng As Range
ColNum = Selection(1).Column
For RowNdx = Selection(Selection.Cells.Count).Row To _
Selection(1).Row + 1 Step -1
If Cells(RowNdx, ColNum).Value = Cells(RowNdx - 1, ColNum).Value
Then
If rng Is Nothing Then
Set rng = Cells(RowNdx, ColNum)
Else
Set rng = Union(rng, Cells(RowNdx, ColNum))
End If
End If
Next RowNdx
If Not rng Is Nothing Then
rng.EntireRow.Delete
End If
End Sub
Les Stout
*** Sent via Developersdex http://www.developersdex.com ***