Macro to Delete Duplicates?

Find a developer for your Excel triggered betting needs and advertise your development service here.

Moderator: 2020vision

Macro to Delete Duplicates?

Postby Betscrew » Sat Mar 19, 2016 3:18 pm

Hi.
Can someone kindly help me with this problem:

I have a worksheet with two sheets. I want to compare column C (header = horse name) in sheet2 to column A (header = horse name) in sheet1.
If there are duplicates found in sheet 1, then I want to delete the entire row in sheet1.

Thanks!
Betscrew
Betscrew
 
Posts: 70
Joined: Mon Jan 27, 2014 10:34 pm

Re: Macro to Delete Duplicates?

Postby Captain Sensible » Sat Mar 19, 2016 6:53 pm

Probably need to explain it a bit better, what are you actually comparing? the Horse name in the header? or just individual rows in the columns ignoring the header completely?
User avatar
Captain Sensible
 
Posts: 2883
Joined: Sat Nov 19, 2005 2:29 pm

Re: Macro to Delete Duplicates?

Postby Betscrew » Sat Mar 19, 2016 7:16 pm

Hi.
Thanks for taking time to reply - I am comparing cell to cell and if finding a match, deleting the entire row - in any case, I manages to solve it myself using something like this


Sub DelDups_TwoLists()
Dim iListCount As Integer
Dim iCtr As Integer

' Turn off screen updating to speed up macro.
Application.ScreenUpdating = False

' Get count of records to search through (list that will be deleted).
iListCount = Sheets("Sheet2").Range("A2:A1000").Rows.Count

' Loop through the "master" list.
For Each x In Sheets("Sheet1").Range("C2:C100")
' Loop through all records in the second list.
For iCtr = 1 To iListCount
' Do comparison of next record.
' To specify a different column, change 1 to the column number.
If x.Value = Sheets("Sheet2").Cells(iCtr, 1).Value Then
' If match is true then delete row.
Sheets("Sheet2").Cells(iCtr, 1).EntireRow.Delete xlShiftUp
' Increment counter to account for deleted row.
iCtr = iCtr + 1
End If
Next iCtr
Next
Application.ScreenUpdating = True
MsgBox "Done!"
End Sub
Betscrew
 
Posts: 70
Joined: Mon Jan 27, 2014 10:34 pm

Re: Macro to Delete Duplicates?

Postby Captain Sensible » Sat Mar 19, 2016 8:11 pm

Good to see you've sorted it and thanks for posting the code up too, you never know when it'll come in useful
User avatar
Captain Sensible
 
Posts: 2883
Joined: Sat Nov 19, 2005 2:29 pm


Return to Find an Excel developer

Who is online

Users browsing this forum: No registered users and 8 guests

Sports betting software from Gruss Software


The strength of Gruss Software is that it’s been designed by one of you, a frustrated sports punter, and then developed by listening to dozens of like-minded enthusiasts.

Gruss is owned and run by brothers Gary and Mark Russell. Gary discovered Betfair in 2004 and soon realised that using bespoke software to place bets was much more efficient than merely placing them through the website.

Gary built his own software and then enhanced its features after trialling it through other Betfair users and reacting to their improvement ideas, something that still happens today.

He started making a small monthly charge so he could work on it full-time and then recruited Mark to help develop the products and Gruss Software was born.

We think it’s the best of its kind and so do a lot of our customers. But you can never stand still in this game and we’ll continue to improve the software if any more great ideas emerge.

cron