Removing duplicates using VBA

Msears

Board Regular
Joined
Apr 14, 2022
Messages
56
Office Version
  1. 365
  2. 2021
  3. 2019
Platform
  1. Windows
Hello All, I am trying to figure out how to modify this existing code. It works good as an initial step. Where it fails is that each time it is pressed, it duplicates existing data. I know I can click remove duplicates, but that is tedious for each of the 12 sheets. Any ideas? Thanks in advance!



VBA Code:
Private Sub SendButton_Click()
   a = Worksheets("Test 3").Cells(Rows.Count, 1).End(xlUp).Row
  
Application.ScreenUpdating = False
  
For i = 2 To a

    If Worksheets("Test 3").Cells(i, 2).Value = "Group Skills" Then
       Worksheets("Test 3").Rows(i).Copy
        Worksheets("Test1").Activate
        b = Worksheets("Test1").Cells(Rows.Count, 1).End(xlUp).Row
        Worksheets("Test1").Cells(b + 1, 1).Select
        Worksheets("Test1").Paste
        Worksheets("Test 3").Activate
           
    End If
Next

Application.CutCopyMode = False

Application.EnableEvents = True

Application.ScreenUpdating = True

ThisWorkbook.Worksheets("Test 3").Cells(2, 1).Select

End Sub
 
Last edited by a moderator:

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Which part was duplicated? It is not clear what you were trying to explain. Perhaps you can install XL2BB and copy paste part of your sample sheet to give better picture.
 
Upvote 0
Which part was duplicated? It is not clear what you were trying to explain. Perhaps you can install XL2BB and copy paste part of your sample sheet to give better picture.
Since this file is on my work pc, I cannot install downloads. Nonetheless. I have screenshots.
In the capture3, shows the original data. Capture4, shows the result after 1 click. Capture5m shows after 2 clicks. The original data is constantly updated for each day, and we want to send it to their designated sheets daily and do not want overlapping data.
 

Attachments

  • Capture3.PNG
    Capture3.PNG
    9.5 KB · Views: 9
  • Capture4.PNG
    Capture4.PNG
    8.7 KB · Views: 9
  • Capture5.PNG
    Capture5.PNG
    11.6 KB · Views: 9
Upvote 0
What is the meaning of Post #4?

If you want only certain people to do your work, just let us know beforehand please.

Try on a copy of the original and check to make sure it does what you want.
Code:
Sub Maybe()
Dim shT3 As Worksheet, shT1 As Worksheet
Dim lr As Long, i As Long
Set shT3 = Worksheets("Test 3")
Set shT1 = Worksheets("Test 1")
shT1.UsedRange.Offset(1).ClearContents
lr = shT3.Cells(Rows.Count, 1).End(xlUp).Row
    For i = 2 To lr
        If shT3.Cells(i, 2).Value = "Group Skills" Then shT1.Cells(Rows.Count, 1).End(xlUp).Offset(1).Resize(, 4).Value = shT3.Cells(i, 2).Offset(, -1).Resize(, 4).Value
    Next i
End Sub
 
Upvote 0
Solution
What is the meaning of Post #4?

If you want only certain people to do your work, just let us know beforehand please.

Try on a copy of the original and check to make sure it does what you want.
Code:
Sub Maybe()
Dim shT3 As Worksheet, shT1 As Worksheet
Dim lr As Long, i As Long
Set shT3 = Worksheets("Test 3")
Set shT1 = Worksheets("Test 1")
shT1.UsedRange.Offset(1).ClearContents
lr = shT3.Cells(Rows.Count, 1).End(xlUp).Row
    For i = 2 To lr
        If shT3.Cells(i, 2).Value = "Group Skills" Then shT1.Cells(Rows.Count, 1).End(xlUp).Offset(1).Resize(, 4).Value = shT3.Cells(i, 2).Offset(, -1).Resize(, 4).Value
    Next i
End Sub
@jolivanes Thanks so much Jolivanes this worked perfectly. As for post #4 disregard, my son had my phone and decided to imitate what I was doing on another post, unbeknownst to me he was on this one and there is not edit button.
 
Upvote 0
OK, thanks for letting us know and the explanation.
Good Luck
 
Upvote 0

Forum statistics

Threads
1,214,643
Messages
6,120,702
Members
448,980
Latest member
CarlosWin

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