+ Reply to Thread
Results 1 to 9 of 9

ListObject.Range.AutoFilter removes incorrectly filters negative numbers

  1. #1
    Registered User
    Join Date
    04-24-2014
    Location
    Pocatello, Idaho
    MS-Off Ver
    Excel 2010
    Posts
    16

    ListObject.Range.AutoFilter removes incorrectly filters negative numbers

    I have an Excel file to help automate my bookkeeping process. A lot of xml files are imported, analyzed, and the data compiled. I use macros to shorten the process. The issue I'm having is that if I filter the table manually on my tender field by the values "creditCards" and "debitCards", it filters correctly, but if I use vba, it incorrectly hides all rows with a negative in the amount field.

    Here is my code:
    Please Login or Register  to view this content.
    where "list" is my ListObject previously defined, Field1 is my CashierID (I need to filter each one separately; this code repeats), and Field4 is my Tender.

    Any ideas as to why this is happening and how to fix it?

  2. #2
    Valued Forum Contributor adyteo's Avatar
    Join Date
    01-10-2013
    Location
    Calgary
    MS-Off Ver
    Excel 2010
    Posts
    540

    Re: ListObject.Range.AutoFilter removes incorrectly filters negative numbers

    what is in this cell: list.Range.AutoFilter Field:=1, Criteria1:=Cells(i, 1).Value
    you also filter by that and that may be the reason
    Click on the star if you think I helped you

  3. #3
    Registered User
    Join Date
    04-24-2014
    Location
    Pocatello, Idaho
    MS-Off Ver
    Excel 2010
    Posts
    16

    Re: ListObject.Range.AutoFilter removes incorrectly filters negative numbers

    That cell contains the Cashier ID, which I have previously extracted from the table. The CashierID does display correctly in all the rows, including those incorrectly filtered, so I do not believe that is the issue.

  4. #4
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: ListObject.Range.AutoFilter removes incorrectly filters negative numbers

    Do you already have other filters in place when that code runs?
    Remember what the dormouse said
    Feed your head

  5. #5
    Registered User
    Join Date
    04-24-2014
    Location
    Pocatello, Idaho
    MS-Off Ver
    Excel 2010
    Posts
    16

    Re: ListObject.Range.AutoFilter removes incorrectly filters negative numbers

    I do not. Upon further debugging, however, I have noticed that this bug only occurs on the first loop through the code, i.e., for the first CashierID. All others run just fine.

    The full loop is as follows:
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    04-24-2014
    Location
    Pocatello, Idaho
    MS-Off Ver
    Excel 2010
    Posts
    16

    Re: ListObject.Range.AutoFilter removes incorrectly filters negative numbers

    So, I figured out a workaround, though I still do not know what is causing the problems. I tried moving Sheets("Import").ShowAllData to the head of the loop, but it threw an error (because all of the data was already shown). So I put a dummy filter before the loop, and then I have that line at the front, and the problem is solved. I really can't figure out why it behaves that way, and if anyone can figure it out, I'm very interested.

  7. #7
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: ListObject.Range.AutoFilter removes incorrectly filters negative numbers

    Sounds like you do have a filter in place beforehand. Pretty hard for us to say how/why without the workbook.

  8. #8
    Registered User
    Join Date
    04-24-2014
    Location
    Pocatello, Idaho
    MS-Off Ver
    Excel 2010
    Posts
    16

    Re: ListObject.Range.AutoFilter removes incorrectly filters negative numbers

    It there is a filter in place beforehand, then why does the ShowAllData method throw an error? I have to create a filter to get that method to work.

  9. #9
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: ListObject.Range.AutoFilter removes incorrectly filters negative numbers

    If the sheet is active, unless the active cell is inside your table, the worksheet.showalldata method will fail - you should use:
    Please Login or Register  to view this content.

+ 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] Clearing out ListObject Filters
    By Dominicus in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-24-2012, 12:56 AM
  2. Inserting negative sign into a range of numbers
    By AM Fernandez in forum Excel General
    Replies: 6
    Last Post: 04-25-2012, 11:14 PM
  3. Applying autofilter removes rows from sight outside of table
    By mcneill_garr in forum Excel General
    Replies: 5
    Last Post: 08-15-2011, 02:32 PM
  4. Replies: 1
    Last Post: 11-20-2008, 01:52 AM
  5. [SOLVED] Converting negative numbers in a range of cells to zero
    By Dede in forum Excel General
    Replies: 3
    Last Post: 01-14-2005, 03:06 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