EXCEL VBA AdvancedFilter CopyToRange in empty table

Roy_Excel_Island_Apps

Board Regular
Joined
Oct 9, 2018
Messages
71
Office Version
  1. 365
Platform
  1. Windows
Hi Guys,

I just wrote a code to get unique customers, but I need to get them in a existing table which I cleared out. What do I have to place after "CopyToRange" to get my data in the table? At this moment, with the existing code, he lists the data at the beginning of the table, but the table doesn't resize. I tried some resize code but this wouldn't help... Thanks in advance!

VBA Code:
Sub GetUniqueCustomerName(tbl As ListObject)

    Dim rng As Range
    Dim tblCustomers As ListObject
    Dim newRow
    Set tblCustomers = shtDASHBOARD.ListObjects("tblCustomers")
   
'Clear the table
    If WorksheetFunction.CountA(shtDASHBOARD.Range("tblCustomers")) > 0 Then
        tblCustomers.DataBodyRange.Delete
    End If
   
'Set range of all customers
    Set rng = tbl.DataBodyRange.Columns(28)
 
'Get the unique customers of the range  
    rng.AdvancedFilter Action:=xlFilterCopy, CopyToRange:=tblCustomers, Unique:=True
   

End Sub
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Hi,

where did you insert the above code?
I'm new to VBA and i can't figured it out.
 
Upvote 0

Forum statistics

Threads
1,215,006
Messages
6,122,665
Members
449,091
Latest member
peppernaut

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