Get unique values from table (Listobject) and import to another Table

aloxaz

New Member
Joined
Aug 29, 2016
Messages
30
Guys,

i m trying to get the unique values from excel table (declare as listobject) and import them to another table (declare as listobject).the issue is that when a paste the values ,the first two values are the same and the table don't resize. Code posted below:

Code:
ActiveSheet.ListObjects("tblNames").ListColumns(1).DataBodyRange.AdvancedFilter Action:=xlFilterCopy, CopyToRange:=ActiveSheet.ListObjects("tblTest2").ListColumns(1).DataBodyRange, Unique:=True

Thanks for helping me out
 

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.
It's a little more code than your one liner, but see if this gets you any closer...

Code:
Sub test()


    Dim tbl As ListObject
    Dim arr
    Dim x As Long
    Dim rng As Range
    
    arr = ActiveSheet.ListObjects("tblNames").ListColumns(1).DataBodyRange
    With CreateObject("Scripting.Dictionary")
        For x = LBound(arr) To UBound(arr)
            If Not IsMissing(arr(x, 1)) Then .Item(arr(x, 1)) = 1
        Next
        arr = .Keys
    End With
    
    Set tbl = ActiveSheet.ListObjects("tblTest2")
    Set rng = Range("tblTest2[#All]").Resize(UBound(arr, 1), tbl.Range.Columns.Count)
    tbl.Resize rng
    tbl.HeaderRowRange.Resize(UBound(arr, 1) + 1).Offset(1).Value = Application.Transpose(arr)
  
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,885
Messages
6,175,184
Members
452,615
Latest member
bogeys2birdies

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