Hi guys
I really need your help in figuring out how to complete the below custom function in Excel.
The idea is simple . What I need is a function that will count unique values on certain worksheets in a defined column which will be the same for all these worksheets (this part is already solved with the below code) , but I want on top of this to report back the unique values given acertain criterion (this part is not solved yet).
Can you pls have a look at the below code and let me know what I am missing.
Thanks in advance for your support
ublic Function MultiSheetUniqueCount(Rng1 As Range, Rng2 As Range, Rng4 As Range, Criterion As Variant)
'Set up a reference to Microsoft Scripting Runtime in Tools > References
Dim Dict As Object
Dim Rng3 As Range
Dim Cell1 As Range
Dim Cell2 As Range
Application.Volatile
Set Dict = CreateObject("Scripting.Dictionary")
For Each Cell1 In Rng1
With Worksheets(Cell1.Value)
Set Rng3 = Intersect(.UsedRange, .Range(Rng2.Address))
If Not Rng3 Is Nothing Then
For Each Cell2 In Rng3
If Cell2.Value <> "" Then
If Dict.Exists(Cell2.Value) Then
'Do nothing
Else
Dict.Add Cell2.Value, Cell2.Value
End If
End If
Next Cell2
End If
End With
Next Cell1
MultiSheetUniqueCount = Dict.Count
End Function
Bookmarks