+ Reply to Thread
Results 1 to 5 of 5

Count of Filtered Data Failing If Then Statement

  1. #1
    Forum Contributor
    Join Date
    06-15-2009
    Location
    Ontario, canada
    MS-Off Ver
    Office 365
    Posts
    371

    Count of Filtered Data Failing If Then Statement

    The code below filters a worksheet (ws_salt) of all rows that fall between an lower date (f_lr) and upper date (f_ur).
    If Then code then determines whether the filter was returned empty.

    In my testing on particular date rate that should be empty, displays empty after the filter is applied, but the "if worksheetFunction.Count(.Cells.SpecialCells(xlCellTypeVisible)) = 0" is failing. It is being treated as though there is filtered data, when it shouldn't. This worksheet does have data in it that doesn't match the filter criteria, so the filter appears to be working (it's coming back empty).

    Please Login or Register  to view this content.
    I use the exact same on another similar worksheet (that doesn't yet contain any data let alone data meeting the criteria) and it works fine.

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

    Re: Count of Filtered Data Failing If Then Statement

    Try:
    Please Login or Register  to view this content.
    The macro assumes you have headers in row 1 and the data starts in row 2.
    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
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,101

    Re: Count of Filtered Data Failing If Then Statement

    f_range is your headers, so counting the number of visible cells on that range will never give 0

  4. #4
    Forum Contributor
    Join Date
    06-15-2009
    Location
    Ontario, canada
    MS-Off Ver
    Office 365
    Posts
    371

    Re: Count of Filtered Data Failing If Then Statement

    Quote Originally Posted by Fluff13 View Post
    f_range is your headers, so counting the number of visible cells on that range will never give 0
    So true. Thanks for bringing that to my attention Fluff.

    I took the if then statement out of the with f_range, and made it of itself ...

    Please Login or Register  to view this content.

  5. #5
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,101

    Re: Count of Filtered Data Failing If Then Statement

    You're welcome & thanks for the feedback

+ 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. Count & Sum in filtered data
    By nagesh.tvsr in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 06-28-2014, 03:57 AM
  2. VBA: Count values on a Filtered data set
    By vidyuthrajesh in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-12-2014, 03:08 PM
  3. get a count of filtered data , count should be as values in cell.
    By prabhuduraraj09 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-14-2012, 06:31 PM
  4. How to use If statement with data that is filtered using AutoFilter?
    By fbarbie in forum Excel Formulas & Functions
    Replies: 23
    Last Post: 06-22-2010, 06:50 PM
  5. count specific value with filtered data
    By Shawn13 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 06-28-2006, 07:30 PM
  6. return row count of filtered data.
    By tarns in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-10-2006, 04:03 AM
  7. Count filtered data only
    By paulharvey in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-18-2005, 02:05 PM

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