Removing Duplicates against Criteria (VBScript)

MyrenG1

New Member
Joined
Jul 2, 2018
Messages
11
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
So this is going to be a challenge, I am looking for a button/Vb script that exports raw data in the below formats on a separate sheet (Detail Export).

Change date/time format to "dd_mm_yyyy".

Remove Duplicate values, See below for details.

Keep Duplicates if:

<style type="text/css">table.tableizer-table{ font-size: 12px; border: 1px solid #CCC ; font-family: Arial, Helvetica,sans-serif; } .tableizer-table td{ padding:4px; margin:3px; border: 1px solid #CCC ;} .tableizer-table th{ background-color: #104E8B ; color:#FFF; font-weight: bold; }</style>[TABLE="class: tableizer-table"]
<tbody>[TR="class: tableizer-firstrow"]
[TH]Type
[/TH]
[TH]ID
[/TH]
[TH]Version
[/TH]
[TH]Date/Time
[/TH]
[TH]Field
[/TH]
[TH]User

[/TH]
[/TR]
[TR]
[TD]Word Doument

[/TD]
[TD]1
[/TD]
[TD]231
[/TD]
[TD]01-06-2018 09:53:28BST
[/TD]
[TD]Removed Text
[/TD]
[TD]Jane
[/TD]
[/TR]
[TR]
[TD]Word Doument

[/TD]
[TD]1
[/TD]
[TD]231
[/TD]
[TD]01-06-2018 09:53:28 BST
[/TD]
[TD]Added Word

[/TD]
[TD]Jane
[/TD]
[/TR]
[TR]
[TD]Word Doument

[/TD]
[TD]1
[/TD]
[TD]231
[/TD]
[TD]01-06-201809:53:28 BST
[/TD]
[TD]Modified Date
[/TD]
[TD]Jane
[/TD]
[/TR]
[TR]
[TD]Word Doument

[/TD]
[TD]1
[/TD]
[TD]232
[/TD]
[TD]01-06-2018 09:53:28 BST
[/TD]
[TD]Removed Text

[/TD]
[TD]Steve
[/TD]
[/TR]
[TR]
[TD]Word Doument

[/TD]
[TD]1
[/TD]
[TD]232
[/TD]
[TD]01-06-201809:53:28 BST
[/TD]
[TD]Added Word
[/TD]
[TD]Steve
[/TD]
[/TR]
[TR]
[TD]Word Doument

[/TD]
[TD]1
[/TD]
[TD]232
[/TD]
[TD]01-06-2018 09:53:28 BST
[/TD]
[TD]Modified Date

[/TD]
[TD]Steve
[/TD]
[/TR]
[TR]
[TD]Excel Sheet

[/TD]
[TD]1
[/TD]
[TD]231
[/TD]
[TD]01-06-2018 09:53:28 BST
[/TD]
[TD]Removed Text

[/TD]
[TD]Jane
[/TD]
[/TR]
[TR]
[TD]Excel Sheet

[/TD]
[TD]1
[/TD]
[TD]231
[/TD]
[TD]01-06-2018 09:53:28 BST
[/TD]
[TD]Added Word

[/TD]
[TD]Jane
[/TD]
[/TR]
[TR]
[TD]Excel Sheet

[/TD]
[TD]1
[/TD]
[TD]231
[/TD]
[TD]01-06-2018 09:53:28 BST
[/TD]
[TD]Modified Date

[/TD]
[TD]Jane
[/TD]
[/TR]
[TR]
[TD]Excel Sheet

[/TD]
[TD]1
[/TD]
[TD]232
[/TD]
[TD]01-06-2018 09:53:28 BST
[/TD]
[TD]Removed Text

[/TD]
[TD]Steve
[/TD]
[/TR]
[TR]
[TD]Excel Sheet

[/TD]
[TD]1
[/TD]
[TD]232
[/TD]
[TD]01-06-2018 09:53:28 BST
[/TD]
[TD]Added Word

[/TD]
[TD]Steve
[/TD]
[/TR]
[TR]
[TD]Excel Sheet

[/TD]
[TD]1
[/TD]
[TD]232
[/TD]
[TD]01-06-2018 09:53:28 BST
[/TD]
[TD]Modified Date

[/TD]
[TD]Steve
[/TD]
[/TR]
</tbody>[/TABLE]


Different User, Same ID, Different Version and Same day. So essentially above each user should have "one change" to their name instead of 3 each for that day for that 1 ID. But also have a "second change" for the different "Type" (Excel Sheet).

I am looking for the data exported to leave behind Type and Unique ID's against Version Number and Day.

Please let me know if you need any clarification.

I have VB script that works for Daily data, but this is required for Monthly Data spread which removed duplicates for the different days as it picks up the same ID against the User. In the "RawData" sheet, "Column A" is a Concatenate of "Column C and G" (ID and Name).

See Script
Code:
Sub Run()
'
' Run Macro
'

  Range("A2:G999999").Select
  Range("A2").Activate
   Application.CutCopyMode = False
    Selection.Copy
    Sheets("DetailExport").Select
   Range("A2").Select
   ActiveSheet.Paste
   Application.CutCopyMode = False
   ActiveSheet.Range("$A$1:$G$999999").RemoveDuplicatesColumns:=Array(3, 7), _
       Header:=xlYes
   Columns("F:F").Select
    Selection.InsertShift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
    Selection.InsertShift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
   Columns("E:E").Select
   Selection.TextToColumns Destination:=Range("E1"),DataType:=xlFixedWidth, _
       FieldInfo:=Array(Array(0, 1), Array(10, 1), Array(19, 1)), TrailingMinusNumbers_
       :=True
   Columns("F:G").Select
   Range("G1").Activate
    Selection.DeleteShift:=xlToLeft
    Dim LR AsLong
    LR =Range("E" & Rows.Count).End(xlUp).Row
   Range("E2").FormulaR1C1 ="=LEFT(VLOOKUP(RC[-4],'RawData'!C[-4]:C,5,false),10)"
   Range("E2").AutoFill Destination:=Range("E2:E" &LR)
   Sheets("Summary").Select
   ActiveWorkbook.RefreshAll
   Range("A1").Select
End Sub
 
Last edited by a moderator:

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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