+ Reply to Thread
Results 1 to 15 of 15

Count unique records in a filtered range

Hybrid View

  1. #1
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259
    Hello jiminic,

    In your last post, is the data in 2 columns or just one? Will the data always be starting in row 3? Are the "MDp" and "XML" portions to be considered when testing for uniqueness?

    Sincerely,
    Leith Ross

  2. #2
    Registered User
    Join Date
    12-11-2006
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel 2007
    Posts
    86
    Hi Leith

    I really appreciate your help with this one.

    The data is in 2 columns, and yes the data will always be starting in row 3. The "MDp" and "XML" portions are not to be considered when testing for uniqueness, only the actual data in row 1.

  3. #3
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259
    Hello jiminic ,

    This macro will count only the unique values in the leftmost column of a selected range or the range supplied to it by code.
    Function GetUniqueCount(Rng As Range)
    
       Dim Cell As Range
       Dim Cnt As Long
       Dim DSO As Object
            
        'Use only the first column of the selected range
         Set Rng = Rng.Resize(Rng.Rows.Count, 1)
         
         Set DSO = CreateObject("Scripting.Dictionary")
         DSO.CompareMode = 1
         
           For Each Cell In Rng
             If Cell <> "" Then
               If Not DSO.Exists(Cell.Text) Then
                  DSO.Add Cell.Text, Cell
                  Cnt = Cnt + 1
               End If
             End If
          Next Cell
        
        Set DSO = Nothing
        GetUniqueCount = Cnt
        
    End Function
    Sincerely,
    Leith Ross

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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