Hello Expert,
I am trying to copy the unique value from a dynamic named range to a range in a worksheet using advancedfilter method every time when value is changed or new data in added to named range. I am facing two problems.
- Every time when new data is entered in named range : 'Test', it gives me runtime error i.e. runtime error28 : Out of stack space
- In filtered result, I want to copy a sum of data corresponding to unique value of named range 'Test' present in column 'Price' of the table as shown in attached workbook. Any lead to achieve it would be helpful.
Please help me resolve this error, and achieve above functionality. Thanks in advance
Code
Private Sub Worksheet_Change(ByVal Target As Range)
Dim cellValue As Variant
Dim coll As New Collection
Dim count As Long
'-----------Counting No. of unique values in named range :'test'-----------------------
Set Target = Range("test")
On Error Resume Next
For Each cellValue In Target.Value
coll.Add cellValue, CStr(cellValue)
Next
count = coll.count
Sheet1.Range("k2") = count
'----------------copying unique values to a range-------------------
Target.AdvancedFilter Action:=xlFilterCopy, copytorange:=Sheet1.Range("K7"), unique:=True
End Sub
Display More