Remove duplicates but keep last ones based on last activity

Shepard

New Member
Joined
Apr 15, 2022
Messages
2
Office Version
  1. 2019
Platform
  1. Windows
Hello,

Allow me to explain my problem. I have the sheet with data on it (16 columns in total). Every day I have to add the new data to the the end of the list and remove duplicates based on three filters (row1: User ID, row2: some data and row4: Last Activity(consists of the dates)). When I process the data manually I don't experience any problem. To simplify my life :) I decided to create two VBA scripts (first to copy the data from external workbook, second to process the data).

for example I have the following data:

users from the previous day:
row1 row2 row4
User ID something last activity
77b 11.04.2022
77a 11.04.2022
77d 11.04.2022

today's users:
66a 12.04.2022
66b 12.04.2022
77d 12.04.2022

I need some solution to keep user 77d which appeared in 12.04.2022 list. When I use macro based on two filters it removes it. When I use three filters a lot of duplicates are not being removed. Could you please have a look at the macros beneath and find out what is wrong? Unfortunately I cannot share the workbook because it includes personal data of the users.

Macros1:

Sub Copy()

Dim FileToOpen As Variant
Dim OpenBook As Workbook
Dim i As Integer
Dim lastrow As Long
Dim verylastrow As Long


If MsgBox("Please make sure you upload Tableau report", vbOKCancel, "Just checking") = vbOK Then

Application.ScreenUpdating = False

FileToOpen = Application.GetOpenFilename(FileFilter:="Comma Separated Values Files (*.csv),*.csv")

If FileToOpen <> False Then

Set OpenBook = Application.Workbooks.Open(FileToOpen)
lastrow = ThisWorkbook.Worksheets("sheet1").Range("B9000").End(xlUp).Row + 1
OpenBook.Sheets(1).Range("A2", Range("O2").End(xlDown)).Copy ThisWorkbook.Worksheets("sheet1").Range("A" & lastrow)
OpenBook.Close savechanges:=False

End If

End If

verylastrow = ThisWorkbook.Worksheets("sheet1").Range("B9000").End(xlUp).Row
For i = lastrow To verylastrow
Cells(i, 16).Value = Date

Next

Application.ScreenUpdating = True
'Process_Data2()
End Sub



Macros2:

Sub Process_Data2()
'
' Process_Data2 Macro
'

'
Range("A1:P2860").Select
Range("E1986").Activate
ActiveSheet.Range("$A$1:$P$1048576").RemoveDuplicates Columns:=Array(1, 2, 4), _
Header:=xlYes
End Sub
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.

Forum statistics

Threads
1,223,911
Messages
6,175,327
Members
452,635
Latest member
laura12345

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