View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
ptrively ptrively is offline
external usenet poster
 
Posts: 10
Default delete rows if value in column D is repeated

I'm not sure if this will help or not, it's a macro I use a lot. As long
as the data is sorted just highlight all the cells in column D and run
this. It might not be perfect, but it should get you in the ball park.

Sub DeleteDuplicate()
'
' DeleteDuplicate Macro
' Macro recorded 1/11/2005 by Paul H. Trively III
'
' Keyboard Shortcut: Ctrl+p
'


Application.ScreenUpdating = False
counter = 0
RNG = Selection.Rows.Count
ActiveCell.Offset(0, 0).Select
baseRow = ActiveCell.Row

For i = 1 To RNG
myCellValue = ActiveCell.Value
myNextCellValue = ActiveCell.Offset(1, 0).Value
If ActiveCell.Value = myNextCellValue Then
For X = 1 To 5000
ActiveCell.Offset(1, 0).Select
If ActiveCell.Value = myNextCellValue Then
counter = counter + 1
Else
X = 5001
End If
Next X
toBaseRow = ActiveCell.Row - 1

ActiveCell.Offset(-counter, 0).Select

Range("A" & baseRow + i, "A" & toBaseRow).Select
Selection.EntireRow.Delete
counter = 0
'If the next cell is the same project number then add it's
value to current and delete
Else
ActiveCell.Offset(1, 0).Select
End If
Next i

Application.ScreenUpdating = True

End Sub