#1   Report Post  
Posted to microsoft.public.excel.misc
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
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Delete duplicates?

Inside the userform module...

Declare a new variable that you can toggle the way you want.

Option Explicit
Dim OkToContinue as boolean
Private Sub CommandButton1_Click()

oktocontinue = true
call CommandButton99_Click
oktocontinue = false

End sub
Private Sub CommandButton99_Click()
'your code

if oktocontinue = false then
unload me
end if
End Sub

Untested, uncompiled.

=========
I think I'd just remove the Unload Me code from the CommandButton99_Click() sub.

Let 'em click the cancel button (or X) to close the form.





WH99 wrote:

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


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 51
Default Delete duplicates?

Thanks Dave,
I went with your last advice....your right! why complicate things
Many thanks
--
WH99


"Dave Peterson" wrote:

Inside the userform module...

Declare a new variable that you can toggle the way you want.

Option Explicit
Dim OkToContinue as boolean
Private Sub CommandButton1_Click()

oktocontinue = true
call CommandButton99_Click
oktocontinue = false

End sub
Private Sub CommandButton99_Click()
'your code

if oktocontinue = false then
unload me
end if
End Sub

Untested, uncompiled.

=========
I think I'd just remove the Unload Me code from the CommandButton99_Click() sub.

Let 'em click the cancel button (or X) to close the form.





WH99 wrote:

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


--

Dave Peterson

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Delete duplicates? kk Excel Discussion (Misc queries) 2 March 14th 08 02:22 PM
How to delete duplicates between workbooks? Jay Excel Worksheet Functions 1 January 23rd 07 03:06 PM
How to delete duplicates between workbooks? Jay Excel Worksheet Functions 0 January 23rd 07 02:58 PM
Delete Duplicates Lauren New Users to Excel 4 April 11th 06 05:46 AM
Delete duplicates Carter68 Excel Worksheet Functions 3 June 15th 05 12:01 AM


All times are GMT +1. The time now is 03:52 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"