VBA change dup values within a group

Sahil123

Well-known Member
Joined
Oct 31, 2011
Messages
673
Hi All,

I was advised to create a new thread as the question is different

I have this code thanks yo Fluff to help me put 0 on duplicates where the name and time (Column A & B) are the same but i came across an issue where i need to check to see if column C
which is the location exists within a group table

So i have table called GroupData and i have all the locations put into a group

I want to apply the same logic as above but also look at the group

In Column C I have the location which will be different however some location are grouped (I have another grouped table called group in another spreadsheet)

GroupedTable (location GroupedFolder\GroupData
Filename GroupedData.xlsx
GroupedTable is on sheet GroupedData


Ie

Birmingham - Group 1
Liverpool - Group 1
London - Group 2
Leicester - Group 3
Bradford - Group 2

I need to amend the code to also look at this table and where there is a match in datetime and Name (Like we currently have)
also look at whether the group location in the same group and only put 0 in the duplicates in that group

ie if Bham, Liverpool and London had same name and time - then keep 1 of the 1 the group 1 data an and put 0's in the other and keep London as that is in another group however if there was another Group 2 ieBradford then have the dups as 0

I was thinking of adding an extra temp column at end of the data set column (AB) will be the column that will be at the end, have a vlookup formula to pull back Group and then do the concatenation check with adding thiscolumn in too

I would have preferred to add this column in memory but that aint a biggie and then just delete out that temp column

is that a better way of doing it?

Here is the existing code

VBA Code:
Sub UpdateDuplicates()
   Dim Cl As Range
   Dim Tmp As String
   
   With CreateObject("scripting.dictionary")
      For Each Cl In Range("A2", Range("A" & Rows.Count).End(xlUp))
         Tmp = Cl.Value2 & "|" & Cl.Offset(, 1).Value
         If Not .exists(Tmp) Then
            .Add Tmp, Nothing
         Else
            Cl.Offset(, 3).Resize(, 2).Value = 0
            Cl.Offset(, 6).Value = 0
         End If
      Next Cl
   End With
End Sub
 

Some videos you may like

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.

Watch MrExcel Video

Forum statistics

Threads
1,113,936
Messages
5,545,105
Members
410,656
Latest member
Hydraulics
Top