Flagging Unique and Duplicate values via VBA

Kiwihiker

New Member
Joined
Nov 16, 2021
Messages
2
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
I have a dataset example - see below. I want to be able to parse the dataset (by VBA, as there may be thousands of records, unless it can be formularised?)) and determine whether a Product (Column B in the attachment) is unique (i.e. does not occur in any other row in a specific column) or, if not unique, flag if the duplicate is the latest instance based on the highest numeric value within a transaction ID (column D). Note that there may be hundreds of duplicates for a given Product.

In a new column (Column G in the attachment), I would like to return TRUE where a Product is unique (i.e. does not occur in any other record) , OR if it is the latest instance of a Product (based on the numeric portion of the transaction ID which are the numbers following the 'TR-' value). Otherwise, return FALSE for that record.

I have manually populated (in Column F) the logiccal result I would like to achieve by code in Column G.

For context, I will use this value as part of an INDEX MATCH criteria from another worksheet to report on the latest instance of a given Product (where part of the MATCH will be whether the cell value is TRUE for a given row).

Cheers

Gerry
FindLatestDuplicate.xlsx
ABCDEF
1AnotherColumnProductYetAnotherColumnTransactionIDAndAnotherColumnUnique/Latest
2Unimportant valueAppleUnimportant valueTR-10001Unimportant valueFALSE
3Unimportant valueBananaUnimportant valueTR-10002Unimportant valueFALSE
4Unimportant valueApricotUnimportant valueTR-10003Unimportant valueTRUE
5Unimportant valuePearUnimportant valueTR-10004Unimportant valueTRUE
6Unimportant valueAppleUnimportant valueTR-1000001Unimportant valueTRUE
7Unimportant valueBananaUnimportant valueTR-10006Unimportant valueFALSE
8Unimportant valueOrangeUnimportant valueTR-10007Unimportant valueFALSE
9Unimportant valueBananaUnimportant valueTR-10008Unimportant valueTRUE
10Unimportant valueAppleUnimportant valueTR-100999Unimportant valueFALSE
11Unimportant valueAppleUnimportant valueTR-100998Unimportant valueFALSE
12Unimportant valueOrangeUnimportant valueTR-100997Unimportant valueTRUE
Sheet1
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
MrExcelPlayground5.xlsx
ABCDEFG
1AnotherColumnProductYetAnotherColumnTransactionIDAndAnotherColumnUnique/LatestUnique/Latest
2Unimportant valueAppleUnimportant valueTR-10001Unimportant valueFALSEFALSE
3Unimportant valueBananaUnimportant valueTR-10002Unimportant valueFALSEFALSE
4Unimportant valueApricotUnimportant valueTR-10003Unimportant valueTRUETRUE
5Unimportant valuePearUnimportant valueTR-10004Unimportant valueTRUETRUE
6Unimportant valueAppleUnimportant valueTR-1000001Unimportant valueTRUETRUE
7Unimportant valueBananaUnimportant valueTR-10006Unimportant valueFALSEFALSE
8Unimportant valueOrangeUnimportant valueTR-10007Unimportant valueFALSEFALSE
9Unimportant valueBananaUnimportant valueTR-10008Unimportant valueTRUETRUE
10Unimportant valueAppleUnimportant valueTR-100999Unimportant valueFALSEFALSE
11Unimportant valueAppleUnimportant valueTR-100998Unimportant valueFALSEFALSE
12Unimportant valueOrangeUnimportant valueTR-100997Unimportant valueTRUETRUE
Sheet4
Cell Formulas
RangeFormula
G2:G12G2=OR(COUNTIF($B$2:$B$12,B2)=1,VALUE(RIGHT(D2,LEN(D2)-3))=SUMPRODUCT(VALUE(RIGHT($D$2:$D$12,LEN($D$2:$D$12)-3)),--($B$2:$B$12=B2),--(VALUE(RIGHT($D$2:$D$12,LEN($D$2:$D$12)-3))=(MAX(VALUE(RIGHT($D$2:$D$12,LEN($D$2:$D$12)-3))*($B$2:$B$12=B2))))))
 
Upvote 0
Solution

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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