Loop Through Sheets To Remove Duplicates

mayoung

Active Member
Joined
Mar 26, 2014
Messages
257
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
How can I modify this code that loops though each sheet and to delete the row based on duplicates in column 3.
Each page has a table and the table name is always different.

VBA Code:
Private Sub RemoveDuplicates()
'
  Application.ScreenUpdating = False

    Dim wsheet As Worksheet
    For Each wsheet In ActiveWorkbook.Worksheets
    If UCase(wsheet.Name) Like "*SHEET*" Then
    Application.DisplayAlerts = False
    wsheet.Range("Table1[#All]").RemoveDuplicates Columns:=3, Header:= _
    xlYes
    Application.DisplayAlerts = True
    End If
    Next
   
  Application.ScreenUpdating = True
     
End Sub
 
Last edited:

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Try this:

VBA Code:
Private Sub RemoveDuplicates()
  Dim ws As Worksheet, tbl As ListObject
  '
  Application.ScreenUpdating = False
  Application.DisplayAlerts = False

  For Each ws In ActiveWorkbook.Worksheets
    If UCase(ws.Name) Like "*SHEET*" Then
      For Each tbl In ws.ListObjects
        tbl.DataBodyRange.RemoveDuplicates Columns:=3, Header:=xlYes
      Next
    End If
  Next
  Application.ScreenUpdating = True
End Sub
 
Upvote 0
Try this:

VBA Code:
Private Sub RemoveDuplicates()
  Dim ws As Worksheet, tbl As ListObject
  '
  Application.ScreenUpdating = False
  Application.DisplayAlerts = False

  For Each ws In ActiveWorkbook.Worksheets
    If UCase(ws.Name) Like "*SHEET*" Then
      For Each tbl In ws.ListObjects
        tbl.DataBodyRange.RemoveDuplicates Columns:=3, Header:=xlYes
      Next
    End If
  Next
  Application.ScreenUpdating = True
End Sub
Worked Perfectly Thank You so much...
 
Upvote 0
I'm glad to help you. Thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,386
Messages
6,124,628
Members
449,176
Latest member
Dazjlbb

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