VBA: Check for duplicates in many to one (or two) relationships

SteveOranjin

Board Regular
Joined
Dec 18, 2017
Messages
170
Hello,

I would like to be able to write a macro that looks for duplicates across "Models". What I mean by this specifically is that, there are certain properties that can exist within our products that must of necessity only occur once. However, due to a different concept of what constitutes a model, often times companies that send us data do not respect this mutually exclusive relationship. I'd like some help uncovering these violations and reporting them. Let me explain what I mean:

A product must of necessity have only one occurrence of any given finish across a model. When we say model, we mean "Subaru Impreza". When we refer to a particular model, or a SKU, we mean "Subaru Impreza - Blue". A model may have 1,2,5 or 10 variations in "SKUs" that represent that model. Often times however, due to poor data standardizations that exist within my industry, companies have different concepts of what a model is. As a result, often times, I will load up a brand's products, and will find that a given model of product has duplicates of the same finish. So in certain sections of our website, where users are not supposed to be able to find such duplicates as these, they are often seeing, "Subaru Impreza - Blue, Subaru Impreza - Green, Subaru Impreza - Blue".

An example of this is below:

ABCD
1ModelSKUNameFinish
2111111-21ToiletBlue
3111111-22ToiletGreen
4111111-23ToiletPurple
5111111-24ToiletBlue
6222222-21Large ToiletBlue
7222222-22Large ToiletGreen
8222222-23Large ToiletPurple
9222222-24Large ToiletBlue

<tbody>
</tbody>

What I'd like help writing a macro with is a macro that can spot when there are duplicates of finish type within a model. So in this case, I'm hoping it is possible to create a macro that will spot the duplicates of a blue finish and return a count of those occurrences to the user, so that they can know to go and look for them. Hoping for some help. If there is a good samaritan who is more skilled than me in VBA and is kind enough to help me, then I would be greatly appreciative of it.

Thanks
 
Hello Steve,

Since you can have a large amount of data, creating a large number of hyperlinks could make the macro very slow. But, I have a few other ideas about streamlining the process.
 
Upvote 0

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Hello Steve,

I added quite a bit to this new version. The "Finish Duplicates" sheet is now hidden. It is now used by a UserForm to list the information on the sheet in a ListBox and breaks down the duplicate rows in ComboBox. Selecting a line in the ListBox will automatically list all of the duplicate rows in the ComboBox. You just click on a row number in the ComboBox and click the "Examine Row" button and you will be taken to that entry on the "Data Sheet". Have a look an let me know what you if this works for you or not.

Bravo Data Loader 3.xlsb
 
Upvote 0
Hello Steve,

I added quite a bit to this new version. The "Finish Duplicates" sheet is now hidden. It is now used by a UserForm to list the information on the sheet in a ListBox and breaks down the duplicate rows in ComboBox. Selecting a line in the ListBox will automatically list all of the duplicate rows in the ComboBox. You just click on a row number in the ComboBox and click the "Examine Row" button and you will be taken to that entry on the "Data Sheet". Have a look an let me know what you if this works for you or not.

Bravo Data Loader 3.xlsb

Hey Leith,

I'm having a couple of problems with it.

1.) If there is more than one duplicate, it treats each separate listing as 1 listing. So, "73,23,42" is interpreted as "732342" and it takes me to that line.
2.) This might be more of an advice thing than anything else, but when I open your sheet, and run one of my older macros, your sheet opens my older version of the sheet and runs the macro there instead. I've got a number of macros in there, that I still need to preserve. If I delete all of my older versions and have just the one you provided in your attachment, will that problem cease?

Besides that, I can't believe how great this thing is. Wow! How long did it take you to become that good at VBA? Thank you so much!

Steve
 
Upvote 0
Hello Steve,

This will fix the problem #1 . Sometimes using Split directly in a For Each loop does not always work correctly, depending on the users system and setup. This method is more robust and I should have used it initially. Here is the updated code for ListBox1's Click event. Replace the code in UserForm1 with the code shown here.

Code:
Private Sub ListBox1_Click()


    Dim Data As Variant
    
        If ListBox1.ListIndex = 0 Then Exit Sub
        
        ComboBox1.Clear
        
        Data = Split(ListBox1.List(ListBox1.ListIndex, 3), ",")
        
        For Each Row In Data
            ComboBox1.AddItem Row
        Next Row
        
        ComboBox1.Value = ComboBox1.List(0)
        ComboBox1.SetFocus
        SendKeys "+{F4}"
        
End Sub

As for question #2 , I am not really sure which old macros and sheets you are referring to. Are these formulas on the sheet or VBA macros. Can you give me an example?

To answer you question about VBA, I am still learning even after 20 years.
 
Last edited:
Upvote 0
Hello Lieth,

(All of this is true minus any additions you have made in the above post.)

So the scenario we're discussing is as follows:

1.) I have two versions of "Bravo Data Loader". One of them is called, "Bravo_Data_Loader_3" (yours) and "Bravo_Data_Loader" (which we'll call mine, which is all the macros I have written into it.)

2.)So when I run, say, "Clear_Data" Macro (I can't recall what it is named off the top off my head) in "Bravo_Data_Loader_3", instead of performing the correct procedure, which is to clear "Data Sheet", it opens "Bravo_Data_Loader" and runs the clear page macro in excel document, in the "Data Sheet" tab there. It is not performing the operation in "Bravo_Data_Loader_3" - that is in the excel document in which I triggered the operation to perform in. This was not happening before . Additionally, if I run the "Clear_Data" macro in "Bravo_Data_Loader" then the "Clear_Data" macro runs in the correct document.

I apologize for the redundancy there. On the internet like this I try to explain things as clearly as possible, and I find the best way to do that is explaining one thing multiple ways.

Hope you are well,

Steve
 
Upvote 0
Lieth,

2#) I was able to solve that problem. The Macro wasn't working when I selected it in the Ribbon I was using. I guess I'll just have to setup that ribbon again.

1.) I am unable to find the macro, "Private Sub ListBox1_Click()". Can I get a hint on how to locate it?

Steve
 
Upvote 0
Hello Steve,

Glad you got it solved. I had no idea you were calling this from the Ribbon.The macro ListBox1_Click() is in UserForm1.
 
Upvote 0
Hello Steve,

Glad you got it solved. I had no idea you were calling this from the Ribbon.The macro ListBox1_Click() is in UserForm1.

Thanks so much leith. That reminds me, one more quick question. Is there a way that I can save the ribbon so it carries with the worksheet so I can send it to someone else and have it be present?

What do I do to do that?

Hope you are well,

Steve
 
Upvote 0
Upvote 0
Hello Steve,

I downloaded the file and opened it. When it tried to open the workbook crashed Excel. When I re-opened the workbook it opened to the "Macro" sheet.

Have you been experiencing these types of problems also? What has been the sequence of the errors you have experienced? What part or parts of the code seem to be failing repeatedly?
 
Upvote 0

Forum statistics

Threads
1,216,030
Messages
6,128,411
Members
449,449
Latest member
Quiet_Nectarine_

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