Vba to remove duplicates from table...

krice1974

Active Member
Joined
Jul 3, 2008
Messages
422
Hello all. I see a lot of resources on removing duplicates but none to reference a table (list object.) The macro recorder grabs it, but I want to refer to the table name with a variable, should be able to be done. Any ideas? Thanks in advance...

Kevin

Code:
Sub RemoveDuplicatesSub(WkSht)
'Remove duplicates.
'Assumes that the data range is in a table
'Assumes the header row starts at row 7, and that the date and number rows are skippped.
 
Dim WS As Worksheet
Dim TableName As String
 
Set WS = Worksheets(WkSht)
TableName = WS.Name & "Table"
 
[COLOR=blue]'This was recorded:[/COLOR]
'WS.Range("Table1[#All]").RemoveDuplicates Columns:=Array(3, 4, 5, 6, 7, 8, 9, 10), Header:=xlYes

[COLOR=#0000ff]'Here is what I'd like to do:[/COLOR]
WS.Range(TableName).RemoveDuplicates Columns:=Array(3, 4, 5, 6, 7, 8, 9, 10), Header:=xlYes
End Sub
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Here's something even more useful, if I could add to my help request? Can I pass the columns to be included in the sub, so maybe the arguments could be (worksheet, columnstart, columnstop)? Thanks again...
 
Upvote 0
I reach out on this one with one final gasp... HELP! :P If you'd be so kind...

I may be a bit behind with this but I was searching for a way to solve the same issue and came up with the following where listobject is your excel table:

Code:
listobject.Range.RemoveDuplicates Columns:=Array(1), Header:=xlYes
 
Upvote 0

Forum statistics

Threads
1,213,567
Messages
6,114,342
Members
448,570
Latest member
rik81h

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