Roy_Excel_Island_Apps
Board Regular
- Joined
- Oct 9, 2018
- Messages
- 68
- Office Version
- 365
- Platform
- 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!
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