+ Reply to Thread
Results 1 to 6 of 6

"<>0" filter error: Not removing "0"/zero values

  1. #1
    Registered User
    Join Date
    10-09-2023
    Location
    USA
    MS-Off Ver
    Version 2306
    Posts
    5

    "<>0" filter error: Not removing "0"/zero values

    Hi all,
    I have been searching and attempting different approaches but have been unsuccessful in this.
    I believe I have attached a simplified example file, and have copied and pasted my code and an image of the incorrect result below as well.
    My first line for "123456789" works correctly, but the second is not filtering out "0" values while keeping all other unique values.
    Any help or suggestions you can offer would be greatly appreciated.
    Thanks in advance.

    Sub FilterTab()
    '
    ' FilterTab Macro
    '
    On Error Resume Next

    Rows("1:1").Select
    Selection.AutoFilter
    ActiveSheet.Range("$A$1").AutoFilter Field:=1, Criteria1:="123456789", Operator:=xlFilterValues
    ActiveSheet.Range("$B$1").AutoFilter Field:=2, Criteria1:="<>0", Operator:=xlFilterValues

    End Sub

    FilterErrorImageOriginal.jpg
    Attached Files Attached Files

  2. #2
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,907

    Re: "<>0" filter error: Not removing "0"/zero values

    The first thing I notice is the green triangle on all of the values in the second field, indicating a "number stored as text" error. I suspect that, when you try to set a criteria like "<>0" the filter is looking for the number 0 and not the text string "0". I see no way to get the filter to search for the text "0" If I convert the numbers stored as text to numbers, the filter for <>0 works just fine.

    I think a lot is going to depend on why you have stored these ID numbers as text strings rather than numbers.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,810

    Re: "<>0" filter error: Not removing "0"/zero values

    Very odd. The value in B64 is not being recognised as 0. Try =0=B64. It returns FALSE. However, it returns 48 for CODE(B64) and 1 for LEN(B64). Even =CODE(B62)=48 returns TRUE. And the formatting is consistent, though that shouldn't make any difference. One of Excel's little foibles.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  4. #4
    Registered User
    Join Date
    10-09-2023
    Location
    USA
    MS-Off Ver
    Version 2306
    Posts
    5

    Re: "<>0" filter error: Not removing "0"/zero values

    Thanks for calling this out MrShorty.
    I added in some additional code that first executes "Texts to Columns" before filtering, which now does what I need it to.
    See below for final VBA code.
    As far as why the numbers are text strings, we are pulling these reports/excel files from a third party vendor's database and this is how they appear after download. So this is what we have to work with unfortunately. But thanks for again for helping me find a simple workaround so that we don't have to waste time with them to update their database and reports.
    Have a great day.

    Sub FilterTab()
    '
    ' FilterTab Macro
    '
    Dim sourceSheet As Worksheet
    Set sourceSheet = ActiveSheet

    On Error Resume Next

    Range("$B$2").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.TextToColumns Destination:=Range("$B$2"), DataType:=xlDelimited, _
    TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
    Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
    :=Array(1, 1), TrailingMinusNumbers:=True

    Rows("1:1").Select
    Selection.AutoFilter
    ActiveSheet.Range("$A$1").AutoFilter Field:=1, Criteria1:="123456789", Operator:=xlFilterValues
    ActiveSheet.Range("$B$1").AutoFilter Field:=2, Criteria1:="<>0", Operator:=xlFilterValues

    End Sub

  5. #5
    Registered User
    Join Date
    10-09-2023
    Location
    USA
    MS-Off Ver
    Version 2306
    Posts
    5

    Re: "<>0" filter error: Not removing "0"/zero values

    Thanks TMS.
    It is strange and as you can see from my above reply quite annoying.
    Luckily I at least now have a workaround to deal with this.
    Enjoy your day.
    Last edited by ams56; 10-09-2023 at 02:27 PM.

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,810

    Re: "<>0" filter error: Not removing "0"/zero values

    You're welcome.

+ 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: 5
    Last Post: 02-05-2019, 12:03 AM
  2. Replies: 0
    Last Post: 02-14-2018, 06:14 PM
  3. [SOLVED] Column X-Ref list - Sheet1 Col A "pages", Col B:FL "Req" to Sheet2 ColA "req", ColB "page"
    By excel-card-pulled in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 04-07-2017, 09:30 AM
  4. Replies: 1
    Last Post: 01-22-2016, 09:21 AM
  5. Replies: 35
    Last Post: 01-13-2016, 02:16 AM
  6. [SOLVED] How to Count number of "Error" and "OK" after the word "Instrument" found in table row
    By eltonlaw in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-17-2012, 06:26 AM
  7. Replies: 3
    Last Post: 02-16-2011, 02:55 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