+ 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,

    Here is macro that will return the row count for a range after it has been filtered.
    Function GetUniqueCount(Rng As Range) As Long
    
      Dim Cnt As Long
      Dim RA As Variant
        
        On Error Resume Next
          Set Rng = Rng.SpecialCells(xlCellTypeVisible)
          If Err = 0 Then
            For Each RA In Rng.Areas
              Cnt = Cnt + RA.Rows.Count
            Next RA
          Else
             Err.Clear
             On Error GoTo 0
          End If
        
        GetUniqueCount = Cnt
        
    End Function
    Sincerely,
    Leith Ross

  2. #2
    Registered User
    Join Date
    12-11-2006
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel 2007
    Posts
    86
    Thank you Leith, how do I make this work though? I can not find the macro name in the list to apply it to a button.

  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,

    The only macros that show up in the Macro List (ALT+F8) are Functions and Subs which don't take arguments. This Sub requires a Range Argument and must be run from within VBA. It cannot be converted to a Function and used as a UDF because Excel will always return the count of all rows in the given range, and not just the filtered ones. It would help to see your workbook.

    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