Macro Needed: Deleting duplicate line items that are not the latest version

matht1234

New Member
Joined
Jul 8, 2013
Messages
2
Hello,

Long time on-looker, first time poster here!

I’m looking to write a Macro to delete multiple line items that pertaining to a common reference number, given that are not reflective of the latest update.

For this problem, my data is downloaded periodically from a separate system and brought into excel to work with. Within the separate system, updates are made to certain reference numbers and dumped into excel. This creates multiple rows of data for the same reference number, and the date of the update. To me, none of the old data is relevant and only the row reflecting the reference number accompanied by the latest update is useful.

The data is in the range from row 2 through 1000.
The assignment numbers are listed in column B.
The dates for these assignment numbers are listed in column D.

In summary, the macro should output no duplicate rows (categorized by reference number) and be accompanied by the date with the latest update (most recent date).

Any help is appreciated.</SPAN></SPAN>

Thanks in advance! You guys are great!
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Data Field A</SPAN>Assignment Number</SPAN>Data Field B</SPAN>ISSUED-DATE</SPAN>Data Field</SPAN>Data Field</SPAN>Data Field</SPAN>Data Field</SPAN>
12</SPAN>12345</SPAN>1</SPAN>3/2/13</SPAN>30</SPAN>xxx</SPAN>pcs</SPAN>O</SPAN>
12</SPAN>12345</SPAN>1</SPAN>3/12/13</SPAN>30</SPAN>xxx</SPAN>pcs</SPAN>O</SPAN>
15</SPAN>99999999</SPAN>1</SPAN>3/12/13</SPAN>100</SPAN>ghy</SPAN>pcs</SPAN>P</SPAN>
43</SPAN>8888888</SPAN>1</SPAN>3/12/13</SPAN>120</SPAN>gpa</SPAN>pcs</SPAN>O</SPAN>
32</SPAN>77777777</SPAN>1</SPAN>3/12/13</SPAN>39</SPAN>hji</SPAN>pcs</SPAN>P</SPAN>
5</SPAN>11199980</SPAN>1</SPAN>4/13/13</SPAN>50</SPAN>yyy</SPAN>pcs</SPAN>P</SPAN>
5</SPAN>11199980</SPAN>1</SPAN>5/6/13</SPAN>50</SPAN>yyy</SPAN>pcs</SPAN>P</SPAN>
5</SPAN>11199980</SPAN>1</SPAN>5/6/13</SPAN>50</SPAN>yyy</SPAN>pcs</SPAN>P</SPAN>
5</SPAN>11199980</SPAN>1</SPAN>5/20/13</SPAN>50</SPAN>yyy</SPAN>pcs</SPAN>P</SPAN>
5</SPAN>11199980</SPAN>1</SPAN>7/1/13</SPAN>50</SPAN>yyy</SPAN>pcs</SPAN>P</SPAN>
5</SPAN>11199980</SPAN>1</SPAN>7/8/13</SPAN>50</SPAN>yyy</SPAN>pcs</SPAN>P</SPAN>
96</SPAN>22299980</SPAN>1</SPAN>4/10/13</SPAN>85</SPAN>mmm</SPAN>pcs</SPAN>O</SPAN>
96</SPAN>22299980</SPAN>1</SPAN>5/12/13</SPAN>85</SPAN>mmm</SPAN>pcs</SPAN>O</SPAN>
96</SPAN>22299980</SPAN>1</SPAN>6/19/13</SPAN>85</SPAN>mmm</SPAN>pcs</SPAN>O</SPAN>
2</SPAN>33399980</SPAN>1</SPAN>3/12/13</SPAN>16</SPAN>qjw</SPAN>pcs</SPAN>P</SPAN>

<TBODY>
</TBODY><COLGROUP><COL><COL><COL><COL><COL span=4></COLGROUP>
 
Upvote 0
try this
Code:
Sub remove_dups()
Dim LR As Long, i As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
For i = LR To 2 Step -1
x = Evaluate("MAX(IF(B:B=" & Cells(i, "B") & ",D:D))")
If Cells(i, "D") <> x Then
    Rows(i).Delete
End If
Next i
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,637
Messages
6,125,964
Members
449,276
Latest member
surendra75

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