VBA to Delete Duplicate Info on Same Date

BigDawg15

Board Regular
Joined
Apr 23, 2018
Messages
72
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hello,

Please see the example below for two dates showing the teams who are playing on those dates. Column I numbers show the team matchups
that are duplicates. I am looking for a macro that would delete the second team matchup for each date. Column I was done manually to give
examples of matches.

Any help or ideas would be appreciated.

Thanks in advance,

BigDawg15

Also posted at:

Dup Teams Example.xlsx
ABCDEFGHI
1RefDateTeam 1InfoDisplay ActivityDivisionTeam 2Game
244436_18/28/2021IllinoisIllinoisBig TenNebraskaIllinois vs Nebraska1
344436_28/28/2021NebraskaNebraskaBig TenIllinoisNebraska vs Illinois1
444436_38/28/2021UTEPUTEPFBS IndependentsNew Mexico StateUTEP vs New Mexico State2
544436_48/28/2021ConnecticutConnecticutMountain WestFresno StateConnecticut vs Fresno State3
644436_58/28/2021New Mexico StateNew Mexico StateConference USAUTEPNew Mexico State vs UTEP2
744436_68/28/2021Fresno StateFresno StateFBS IndependentsUConnFresno State vs UConn3
844436_78/28/2021Hawai'iHawai'iPac-12UCLAHawai'i vs UCLA4
944436_88/28/2021San José StateSan José StateBig SkySouthern UtahSan José State vs Southern Utah9
1044436_98/28/2021UCLAUCLAMountain WestHawai'iUCLA vs Hawai'i4
1144442_19/3/2021DukeDukeConference USACharlotteDuke vs Charlotte5
1244442_29/3/2021North CarolinaNorth CarolinaACCVirginia TechNorth Carolina vs Virginia Tech6
1344442_39/3/2021Virginia TechVirginia TechACCNorth CarolinaVirginia Tech vs North Carolina6
1444442_49/3/2021Wake ForestWake ForestConference USAOld DominionWake Forest vs Old Dominion7
1544442_59/3/2021KansasKansasMissouri ValleySouth DakotaKansas vs South Dakota10
1644442_69/3/2021Michigan StateMichigan StateBig TenNorthwesternMichigan State vs Northwestern8
1744442_79/3/2021NorthwesternNorthwesternBig TenMichigan StateNorthwestern vs Michigan State8
1844442_89/3/2021CharlotteCharlotteACCDukeCharlotte vs Duke5
1944442_99/3/2021Old DominionOld DominionACCWake ForestOld Dominion vs Wake Forest7
2044442_109/3/2021Notre DameNotre DameACCFlorida StateNotre Dame vs Florida State8
2144442_119/3/2021Eastern MichiganEastern MichiganNortheastSt Francis (PA)Eastern Michigan vs St Francis (PA)11
2244442_129/3/2021Colorado StateColorado StateMissouri ValleySouth Dakota StateColorado State vs South Dakota State12
2344442_139/3/2021ColoradoColoradoBig SkyNorthern ColoradoColorado vs Northern Colorado13
2444442_149/3/2021Florida StateFlorida StateFBS IndependentsNotre DameFlorida State vs Notre Dame8
Sheet1
Cell Formulas
RangeFormula
E2:E24E2=IF(ISBLANK(B2),"",C2)
H2:H24H2=C2 & " vs " & G2
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
In your example all duplicates can be "removed" except for this game, since "Connecticut" does not have the same name in the second game.

varios 05jun2021.xlsm
ABCDEFGHI
1RefDateTeam 1InfoDisplay ActivityDivisionTeam 2Game
244436_48/28/2021ConnecticutConnecticutMountain WestFresno StateConnecticut vs Fresno State3
344436_68/28/2021Fresno StateFresno StateFBS IndependentsUConnFresno State vs UConn3
Hoja6



Try the following macro. The results of the unique games will be on sheet2 from cell A2.

VBA Code:
Sub Delete_Matchup()
  Dim dic As Object
  Dim a As Variant, b As Variant
  Dim i As Long, j As Long, k As Long
  Dim game1 As String, game2 As String
  
  Set dic = CreateObject("Scripting.Dictionary")
  a = Sheets("Sheet1").Range("A2", Sheets("Sheet1").Range("H" & Rows.Count).End(3)).Value
  ReDim b(1 To UBound(a, 1), 1 To UBound(a, 2))
  
  For i = 1 To UBound(a, 1)
    game1 = a(i, 2) & "|" & a(i, 3) & "|" & a(i, 7)
    game2 = a(i, 2) & "|" & a(i, 7) & "|" & a(i, 3)
    If Not dic.exists(game1) And Not dic.exists(game2) Then
      dic(game1) = Empty
      k = k + 1
      For j = 1 To UBound(a, 2)
        b(k, j) = a(i, j)
      Next
    End If
  Next
  
  Sheets("Sheet2").Range("A2").Resize(k, UBound(b, 2)).Value = b
End Sub
 
Upvote 1
Solution
Dante,

Thank you for the reply. I want to keep one of the duplicates, and any that do not have a duplicate. So in my example, numbers 1, 2, 3 each have a duplicate.
I would like to remove one of them and keep the other. Doesn't matter which one is deleted. I also want to keep 10, 11, 12, & 13 because they do not have
a duplicate.

Thank you again for assistance.

BigDawg15
 
Upvote 0
At first I did not try the macro. I was going by what you had written. It did not sound like you had understood my request. I have now tried it and it seems to
be working as requested.

Thank you very much for your time and help,

Regards,

BigDawg15
 
Upvote 0
I want to modify the code so that there are two columns of values that I want to sum their values for the duplicate
The result is as follows:
100002418-08-20211012600133203
100002412-08-202120226001779099
100002417-06-20212126007785743

 

Attachments

  • duplicate.jpg
    duplicate.jpg
    93.3 KB · Views: 6
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,287
Members
452,902
Latest member
Knuddeluff

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top