VBA Multiple Critea Delete Duplicate Values

JaysVBA

New Member
Joined
Mar 4, 2014
Messages
2
Hello All,

I just took my first VBA course and brand new to the forum. I was hoping for some help in deleting duplicate values based off of multiple criterea. Each item has a unique Sec Code. I do not care about the "Group column." My desired results will show the security codes with all of the unique rates. Item 1 has 3 different rates (text color red in the desired results). So ideally, I would like to delete duplicates on items that have the same sec code and rate.

Any help would be greatly appreciated.
- JaysVBA

Raw Data</SPAN>
Group</SPAN>Sec Code</SPAN>Item Name</SPAN>Purchase</SPAN> Pay Date</SPAN>Rate</SPAN>
12345</SPAN>11396Q102</SPAN>Item 1</SPAN>08-Jan-14</SPAN>03-Feb-14</SPAN>0.45</SPAN>
12345</SPAN>123456789</SPAN>Item 2</SPAN>13-Jan-14</SPAN>17-Feb-14</SPAN>0.23</SPAN>
ABCD</SPAN>11396Q102</SPAN>Item 1</SPAN>08-Jan-14</SPAN>03-Feb-14</SPAN>0.45</SPAN>
ABCD</SPAN>035710411</SPAN>Item 3</SPAN>27-Dec-13</SPAN>31-Jan-14</SPAN>0.3</SPAN>
ABCD</SPAN>11396Q102</SPAN>Item 1</SPAN>27-Dec-13</SPAN>31-Jan-14</SPAN>0.4</SPAN>
6789</SPAN>11396Q102</SPAN>Item 1</SPAN>08-Jan-14</SPAN>03-Feb-14</SPAN>0.48</SPAN>
6789</SPAN>123456789</SPAN>Item 2</SPAN>13-Jan-14</SPAN>17-Feb-14</SPAN>0.23</SPAN>
6789</SPAN>00287Y109</SPAN>Item 4</SPAN>13-Jan-14</SPAN>14-Feb-14</SPAN>0.4</SPAN>
Desired Results</SPAN>
Group</SPAN>Sec Code</SPAN>Item Name</SPAN>Purchase</SPAN> Pay Date</SPAN>Rate</SPAN>
12345</SPAN>11396Q102</SPAN>Item 1</SPAN>08-Jan-14</SPAN>03-Feb-14</SPAN>0.45</SPAN>
12345</SPAN>123456789</SPAN>Item 2</SPAN>13-Jan-14</SPAN>17-Feb-14</SPAN>0.23</SPAN>
ABCD</SPAN>035710411</SPAN>Item 3</SPAN>27-Dec-13</SPAN>31-Jan-14</SPAN>0.3</SPAN>
ABCD</SPAN>11396Q102</SPAN>Item 1</SPAN>27-Dec-13</SPAN>31-Jan-14</SPAN>0.4</SPAN>
6789</SPAN>11396Q102</SPAN>Item 1</SPAN>08-Jan-14</SPAN>03-Feb-14</SPAN>0.48</SPAN>
6789</SPAN>00287Y109</SPAN>Item 4</SPAN>13-Jan-14</SPAN>14-Feb-14</SPAN>0.4</SPAN>

<TBODY>
</TBODY><COLGROUP><COL><COL><COL><COL span=2><COL></COLGROUP>
 

bzelenak

New Member
Joined
Mar 7, 2014
Messages
2
Maybe add a column (lets call it column X) in which you concatenate Sec Code and Rate, and then remove duplicates. Then delete column X.
 

bzelenak

New Member
Joined
Mar 7, 2014
Messages
2
If all you care about is Sec Code and Rate, then maybe insert a new column (lets call it column X) in which you concatenate the fields you care about (Sec Code and Rate). Then remove duplicates and delete column X.
 

JaysVBA

New Member
Joined
Mar 4, 2014
Messages
2
Thank you. I like the concatenate idea but I would like this to be a part of a larger macro. I assume I could just record such function but is there a simpler way using vba?
 

mirabeau

Banned user
Joined
Nov 4, 2010
Messages
2,075
Thank you. I like the concatenate idea but I would like this to be a part of a larger macro. I assume I could just record such function but is there a simpler way using vba?
Code:
Sub dxxd()

Dim d As Object, a, u, i As Long, j As Long
Set d = CreateObject("scripting.dictionary")

With Range("A1").CurrentRegion.Resize(, 6)
    a = .Value
    For i = 2 To .Rows.Count
        u = a(i, 2) & Chr(30) & a(i, 6)
        If Not d.exists(u) Then
            d.Add u, Nothing
            For j = 1 To 6
                a(d.Count + 1, j) = a(i, j)
            Next j
        End If
    Next i
    .ClearContents
    .Resize(d.Count + 1, 6) = a
End With

End Sub
There is a RemoveDuplicates facility in Excell 2007 and on that should do the same when it works, but it may have a bug. Check google on that one.
 

C Moore

Active Member
Joined
Jan 17, 2014
Messages
431
click a cell in your data
Code:
Sub remove_dupes
ActiveCell.CurrentRegion.RemoveDuplicates Columns:=Array(2, 6), Header:=xlYes
End Sub
 

Forum statistics

Threads
1,081,849
Messages
5,361,673
Members
400,644
Latest member
ndroger1

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top