Need Help with My VBA Code

Giovanni03

New Member
Joined
May 23, 2023
Messages
33
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
Hello Everyone!

I currently have a code that I'm using to delete duplicate rows, i believed it was working but running a lot of test on my file and of course I found that its not deleting all of the duplicate data. Its working just not 100%. I'm hoping you guys could assist me with this code and see how I can improve it so I can truly delete all duplicate rows.

My Sheet has 14 Columns(A-N). The main place the duplicated data will be in is from column A to D (First 4 columns).

Here's the code that I'm using.

VBA Code:
Sub DeleteRows()

    With ActiveSheet
        Set Rng = Range("A2", Range("N2").End(xlDown))
        Rng.RemoveDuplicates Columns:=Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14), Header:=xlYes
    End With
End Sub
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Hello Everyone!

I currently have a code that I'm using to delete duplicate rows, i believed it was working but running a lot of test on my file and of course I found that its not deleting all of the duplicate data. Its working just not 100%. I'm hoping you guys could assist me with this code and see how I can improve it so I can truly delete all duplicate rows.

My Sheet has 14 Columns(A-N). The main place the duplicated data will be in is from column A to D (First 4 columns).

Here's the code that I'm using.

VBA Code:
Sub DeleteRows()

    With ActiveSheet
        Set Rng = Range("A2", Range("N2").End(xlDown))
        Rng.RemoveDuplicates Columns:=Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14), Header:=xlYes
    End With
End Sub
Please show us some sample data that it is not working on.
Please show us BEFORE and AFTER images.
 
Upvote 0
@Joe4 The highlighted rows are the ones that are duplicated. When I run the code it does not delete them.

DuplicateRows.xlsx
ABCDEFGHIJKLMN
1Order NumberFulfillment TypeSKUProduct DescriptionCustomer First NameCustomer Last NameCustomer NameRoute.RouteDayRoute.RouteNameRoute.locationkeyRoute.CustomerNameRoute.StopProjectedBegunRoute.StopProjectedCompleteRoute.Service Time
2Order # 41703RETURN6420142Product # 1JohnDoeJohn Doe6/26/2023Route # 0389987659John Doe6/26/2023 12:076/26/2023 12:321/0/1900 0:25
3Order # 41703RETURN6420142Product # 1JohnDoeJohn Doe6/26/2023Route # 0390253366John Doe6/26/2023 11:426/26/2023 12:071/0/1900 0:25
4Order # 41703DELIVERY6420142Product # 2JohnDoeJohn Doe6/26/2023Route # 0389987659John Doe6/26/2023 12:076/26/2023 12:321/0/1900 0:25
5Order # 41703DELIVERY6420142Product # 2JohnDoeJohn Doe6/26/2023Route # 0390253366John Doe6/26/2023 11:426/26/2023 12:071/0/1900 0:25
6Order # 41703SERVICE5246500Product # 3JohnDoeJohn Doe6/26/2023Route # 0389987659John Doe6/26/2023 12:076/26/2023 12:321/0/1900 0:25
7Order # 41703SERVICE5246500Product # 3JohnDoeJohn Doe6/26/2023Route # 0390253366John Doe6/26/2023 11:426/26/2023 12:071/0/1900 0:25
8Order # 41703DELIVERY8930357Product # 4JohnDoeJohn Doe6/26/2023Route # 0389987659John Doe6/26/2023 12:076/26/2023 12:321/0/1900 0:25
9Order # 41703DELIVERY8930357Product # 4JohnDoeJohn Doe6/26/2023Route # 0390253366John Doe6/26/2023 11:426/26/2023 12:071/0/1900 0:25
10Order # 41703DELIVERY9282812Product # 5JohnDoeJohn Doe6/26/2023Route # 0389987659John Doe6/26/2023 12:076/26/2023 12:321/0/1900 0:25
11Order # 41703DELIVERY9282812Product # 5JohnDoeJohn Doe6/26/2023Route # 0390253366John Doe6/26/2023 11:426/26/2023 12:071/0/1900 0:25
12Order # 43777RETURN5963916Product # 1JohnDoe #2John Doe #26/26/2023Route # 0389987659John Doe6/26/2023 12:076/26/2023 12:321/0/1900 0:25
13Order # 43777RETURN5963916Product # 1JohnDoe #2John Doe #26/26/2023Route # 0390253366John Doe6/26/2023 11:426/26/2023 12:071/0/1900 0:25
14Order # 43777DELIVERY5963916Product # 2JohnDoe #2John Doe #26/26/2023Route # 0389987659John Doe6/26/2023 12:076/26/2023 12:321/0/1900 0:25
15Order # 43777DELIVERY5963916Product # 2JohnDoe #2John Doe #26/26/2023Route # 0390253366John Doe6/26/2023 11:426/26/2023 12:071/0/1900 0:25
16Order # 43777SERVICE5246401Product # 3JohnDoe #2John Doe #26/26/2023Route # 0389987659John Doe6/26/2023 12:076/26/2023 12:321/0/1900 0:25
17Order # 43777SERVICE5246401Product # 3JohnDoe #2John Doe #26/26/2023Route # 0390253366John Doe6/26/2023 11:426/26/2023 12:071/0/1900 0:25
Sheet1
 
Upvote 0
Oh Snap! I just noticed the issue!

So super quick background on the file, its basically a merged file and during the merging process I have to use fuzzy option(no choice) which creates dups. typically this code works so I was really stuck as to why it wasn't working....

Staring at this long enough I found that In column J the key got mixed between two different orders (Same Customer Name) which made it so the code wont delete the duplicate rows. (tech not duplicated at that point).

Now I have to figure out how to stop this issue while merging the same customer name different orders.
 
Upvote 0
Oh Snap! I just noticed the issue!

So super quick background on the file, its basically a merged file and during the merging process I have to use fuzzy option(no choice) which creates dups. typically this code works so I was really stuck as to why it wasn't working....

Staring at this long enough I found that In column J the key got mixed between two different orders (Same Customer Name) which made it so the code wont delete the duplicate rows. (tech not duplicated at that point).

Now I have to figure out how to stop this issue while merging the same customer name different orders.
OK, so does that mean that this issue is solved?
It sounds like now the issue is with the data generation, which isn't anything with the code you posted, right?
 
Upvote 0
OK, so does that mean that this issue is solved?
It sounds like now the issue is with the data generation, which isn't anything with the code you posted, right?
Yup, deff no issue with the code, it was the data itself.
 
Upvote 0

Forum statistics

Threads
1,223,229
Messages
6,170,881
Members
452,364
Latest member
springate

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