+ Reply to Thread
Results 1 to 19 of 19

Count Unique values in multiple worksheets based on certain criteria

Hybrid View

  1. #1
    Registered User
    Join Date
    03-05-2019
    Location
    Cyprus
    MS-Off Ver
    Microsoft Excel for Office 365 MSO (16.0.10730.20280) 64-bit
    Posts
    9

    Count Unique values in multiple worksheets based on certain criteria

    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

  2. #2
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 365
    Posts
    8,028

    Re: Count Unique values in multiple worksheets based on certain criteria

    Can you attach a copy of your file? Explain in detail want you want to do referring to specific cells, rows, columns and sheets. De-sensitize the data if necessary.
    You can say "THANK YOU" for help received by clicking the Star symbol at the bottom left of the helper's post.
    Practice makes perfect. I'm very far from perfect so I'm still practising.

  3. #3
    Registered User
    Join Date
    03-05-2019
    Location
    Cyprus
    MS-Off Ver
    Microsoft Excel for Office 365 MSO (16.0.10730.20280) 64-bit
    Posts
    9

    Re: Count Unique values in multiple worksheets based on certain criteria

    Hi Mumps1

    I do appreciate your fast response on this , I am attaching the relevant excel file for you to check.
    As you can see the VBA formula in cell D2 and D3 in worksheet under the name "Master Table" it reads worksheets Lights_Utilisation & door Utilisation in column B:B and it returns the count of unique instances . Now what I want is for these unique instances to be also restricted on the values of column c:c of the "Master Table" , so when the formula works correctly the right numbers should be for Cyprus = 365 and for Greece = 5063 , now in both countries the formula returns the value of 5429.

    Let me know if I have now explained in a more thorough manner
    Thanks again for your generous offering to help me
    Regards
    Kyuss 21
    Attached Files Attached Files

  4. #4
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 365
    Posts
    8,028

    Re: Count Unique values in multiple worksheets based on certain criteria

    Cells B2 and B3 in the Master Table contain "GREECE & CYPRUS". Should B2 and B3 contain "Lights_Utilisation" and " Doors_Utilisation" respectively? Do you want to find the count of "Cyprus" and "Greece" in sheets "Lights_Utilisation" and "Doors_Utilisation" and if so, in which columns in the Master do you want to put the counts for each? Please clarify in detail referring to specific cells, rows, columns and sheets.

  5. #5
    Registered User
    Join Date
    03-05-2019
    Location
    Cyprus
    MS-Off Ver
    Microsoft Excel for Office 365 MSO (16.0.10730.20280) 64-bit
    Posts
    9

    Re: Count Unique values in multiple worksheets based on certain criteria

    The formula should lookup value C2 in the Master Table and return the number of 365 in cell D2 and lookup the value C3 in the Master Table and return the number of 5063 in cell D3 in the Master Table.

  6. #6
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 365
    Posts
    8,028

    Re: Count Unique values in multiple worksheets based on certain criteria

    Place this formula in D2 and copy it down: =COUNTIF(Lights_Utilisation!A$2:A$6000,C2)

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] SUMPRODUCT function count the Unique values based on Multiple criteria
    By savetrees in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 01-15-2018, 04:03 AM
  2. Replies: 11
    Last Post: 11-16-2017, 07:11 AM
  3. Count unique values based on multiple criteria
    By Jonathan11235 in forum Excel Formulas & Functions
    Replies: 13
    Last Post: 05-19-2015, 10:02 PM
  4. count unique values in multiple worksheets with multiple criteria
    By craig04 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 10-06-2012, 03:26 PM
  5. [SOLVED] how to count unique values in excel based on multiple criteria
    By IDBUGM in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 03-15-2006, 12:10 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1