View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.misc
WH99 WH99 is offline
external usenet poster
 
Posts: 51
Default Delete duplicates?

I have the following code below. This one I got from Dave Paterson.
It works very well.
I have used this code in UserForm1 (commandbutton1), so when pressed it
closes the form after deleting duplicates. I have added a vbYesNo to
commandbutton1 so that now it ask if you wish to continue yes or no.
Selecting "No" it runs the code below, but when selecting "Yes" I cant get it
to run the code below to delete duplicates and leave the form open. It high
lights "Dim lastrow as Object" which is in commandbutton1 code. Any ideas?


Option Explicit
Private Sub CommandButton99_Click()

Dim iRow As Long
Dim FirstRow As Long
Dim LastRow As Long
Dim wks As Worksheet

For Each wks In Worksheets(Array("customers", "customers2"))
With wks
FirstRow = 2 'headers in row 1
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row

For iRow = FirstRow To LastRow Step 1
If Application.CountIf(.Range("a1").EntireColumn, _
.Cells(iRow, "A").Value) 1 Then
'it's a duplicate
.Rows(iRow).Delete
End If
Next iRow
End With
Next wks

Unload Me

End Sub

--
WH99