+ Reply to Thread
Results 1 to 4 of 4

VBA to Count Rows and then AutoFilter range

  1. #1
    Registered User
    Join Date
    02-23-2015
    Location
    Calgary
    MS-Off Ver
    Office 2010
    Posts
    8

    VBA to Count Rows and then AutoFilter range

    Hello,

    I have some code I use to auto filter a spreadsheet with 2 criteria and in two sections. The problem is I don't know how big the data will be and I currently have it set for 1 million rows but will often need more, if I set it for 1.5 million, if I don't have that many rows I get an error. Is there a way to ensure I count the rows and then apply the autofilter to the exact amount of rows I need? Below is the code I am using:

    ActiveSheet.Range("$A$1:$Q$1000001").AutoFilter Field:=14, Criteria1:=Array( _
    "Cashback", "Cheque Cashing", "Deposit", "End Of Customer Session", "FX Deposit", _
    "FX Make Change", "FX Withdrawal", "Make Change", "Withdrawal"), Operator:= _
    xlFilterValues
    Range("A1").Select
    ActiveSheet.Range("$A$1:$Q$1000001").AutoFilter Field:=1, Criteria1:="<>"

  2. #2
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: VBA to Count Rows and then AutoFilter range

    Maybe:

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    02-23-2015
    Location
    Calgary
    MS-Off Ver
    Office 2010
    Posts
    8

    Re: VBA to Count Rows and then AutoFilter range

    AWESOME - thank you so much! You've taught me something I will use a lot...

  4. #4
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: VBA to Count Rows and then AutoFilter range

    You're welcome. Glad to help out and thanks for the feedback. Please comply with Forum Rules and mark this thread as solved. Refer to the rules below for guidance.

    http://www.excelforum.com/forum-rule...rum-rules.html

+ 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. Replies: 2
    Last Post: 01-21-2014, 11:34 PM
  2. autofilter, visible rows count error
    By florin_excel in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-24-2013, 11:22 AM
  3. [SOLVED] count rows after autofilter
    By opie546 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-26-2012, 02:35 PM
  4. Count remaining rows after autofilter has been applied
    By walshy06 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-06-2006, 06:40 PM
  5. How do I count rows in a filtered list when using AutoFilter?
    By chiefcook in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 12-22-2005, 10:10 AM

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