Macro to remove duplicates & then order list by date

saitken

New Member
Joined
Jan 6, 2013
Messages
39
Office Version
  1. 365
Platform
  1. MacOS
Hello. Can anyone help me with a Macro that copies a list of data from Sheet 1 to Sheet 2 and then removes duplicates and orders the list by 'Finish Date'.
Please see my data and the output I want.
Data in Sheet 1.
Copy to Sheet 2.
Remove the duplicates from 'Description' column in Sheet 2.
Then order the list by 'Finish Date', oldest to newest in Sheet 2
Thank you

1687177145988.png
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Try this:

VBA Code:
Sub remove_duplicates_order_by_date()
  Dim sh1 As Worksheet, sh2 As Worksheet
  Dim lr As Long
  
  Set sh1 = Sheets("Sheet1")
  Set sh2 = Sheets("Sheet2")
  lr = sh1.Range("G" & Rows.Count).End(3).Row
  
  sh2.Range("A2").Resize(lr - 4).Value = sh1.Range("G5:G" & lr).Value
  sh2.Range("D2").Resize(lr - 4).Value = sh1.Range("AV5:AV" & lr).Value
  sh2.Range("E2").Resize(lr - 4).Value = sh1.Range("AW5:AW" & lr).Value
  With sh2.Range("A1:E1").Resize(lr - 3)
    .RemoveDuplicates Columns:=Array(1, 4, 5), Header:=xlYes
    .Sort sh2.Range("E1"), xlAscending, Header:=True
  End With
End Sub

--------------
Let me know the result and I'll get back to you as soon as I can.
Cordially
Dante Amor
--------------​
 
Upvote 0
Solution
Sub remove_duplicates_order_by_date() Dim sh1 As Worksheet, sh2 As Worksheet Dim lr As Long Set sh1 = Sheets("Sheet1") Set sh2 = Sheets("Sheet2") lr = sh1.Range("G" & Rows.Count).End(3).Row sh2.Range("A2").Resize(lr - 4).Value = sh1.Range("G5:G" & lr).Value sh2.Range("D2").Resize(lr - 4).Value = sh1.Range("AV5:AV" & lr).Value sh2.Range("E2").Resize(lr - 4).Value = sh1.Range("AW5:AW" & lr).Value With sh2.Range("A1:E1").Resize(lr - 3) .RemoveDuplicates Columns:=Array(1, 4, 5), Header:=xlYes .Sort sh2.Range("E1"), xlAscending, Header:=True End With End Sub
Superb. Thanks you very much. Worked first time.
Stewart
 
Upvote 0
Hi. I have realised that I need this brilliant Macro to be tweaked.
I have two sets of data identified as 'Phase 1' and 'Phase 2'. Each identified with an 'x' in columns I & J.
I want to be able to run the macro for 'Phase 1' data, which has an 'x' in column I.
And then run it again for 'Phase 2' data, which has an 'x' in column J.

Sheet 1:
1687263462565.png


Sheet 2 (required output):
1687263501116.png


How would I update your Macro to do this please?

Thank you
 
Upvote 0
Hi saitken.
You should mark the post that actually solved your original problem. Unless your own answer is the solution.
 
Upvote 0
I have two sets of data identified as 'Phase 1' and 'Phase 2'. Each identified with an 'x' in columns I & J.
I want to be able to run the macro for 'Phase 1' data, which has an 'x' in column I.
And then run it again for 'Phase 2' data, which has an 'x' in column J.
It seems to be a new requirement, the macro must be changed, create a new thread.
🤗
 
Upvote 0

Forum statistics

Threads
1,215,097
Messages
6,123,077
Members
449,094
Latest member
mystic19

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