+ Reply to Thread
Results 1 to 9 of 9

Help:Excel VBA to filter all 0 in the data table with formulae

  1. #1
    Registered User
    Join Date
    04-23-2024
    Location
    London
    MS-Off Ver
    Microsoft 365
    Posts
    6

    Question Help:Excel VBA to filter all 0 in the data table with formulae

    I tried to write VBA to autoFilter all the 0 number in the table at the "Total AUM" column in the worksheet.
    All the numbers in the table are the results of the formulae from a different
    However, the VBA filter all columns when i run the macro.
    Could someone please help to check what the issues are?
    Thanks.

    Table BankSum
    Name Total Aum CCY Rebate
    Ariel 999,888.44 HKD 22.55
    Ben - - -
    Coman 258,369.11 SGD 3,445.66
    Don - TWD 55.66



    VBA
    Sub FilterZeroDecimalFormulas()
    ---Dim ws As Worksheet
    ---Dim tbl As ListObject
    ---Dim filterColumn As Integer
    ---Dim cell As Range
    ---Dim rng As Range
    ---Dim criteria As String
    ---Dim nonZeroValues As Collection
    ---Dim val As Variant

    ---Set ws = ThisWorkbook.Sheets("Bank")

    ---Set tbl = ws.ListObjects("BankSum")

    ---filterColumn = 2

    ---If tbl.ShowAutoFilter Then
    ------tbl.AutoFilter.ShowAllData
    ---End If

    ---Set rng = tbl.ListColumns(filterColumn).DataBodyRange

    ---Set nonZeroValues = New Collection

    ---For Each cell In rng
    ------If cell.HasFormula And cell.Value <> 0 Then
    ---------On Error Resume Next
    ---------nonZeroValues.Add cell.Value, CStr(cell.Value)
    ---------On Error GoTo 0
    ------End If
    ---Next cell

    ---For Each val In nonZeroValues
    ------If criteria = "" Then
    ------criteria = "=" & val
    ------Else
    ---------criteria = criteria & "," & "=" & val
    ------End If
    ---Next val

    ---If criteria <> "" Then
    ------tbl.Range.AutoFilter Field:=filterColumn, Criteria1:=Split(criteria, ","), Operator:=xlFilterValues
    ---End If
    End Sub

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,064

    Re: Help:Excel VBA to filter all 0 in the data table with formulae

    You need to add code tags to your post, not use dashes for indentation.

    Quote Originally Posted by gerrardowen View Post
    However, the VBA filter all columns when i run the macro.
    I'm not sure what you mean by that. If you mean that it's hiding complete rows, then yes, that is how filters work.
    Everyone who confuses correlation and causation ends up dead.

  3. #3
    Registered User
    Join Date
    04-23-2024
    Location
    London
    MS-Off Ver
    Microsoft 365
    Posts
    6

    Re: Help:Excel VBA to filter all 0 in the data table with formulae

    i want to filter the complete rows which the "Total AUM" have "-"
    So the VBA should be filter "Ben" & "Don" rows, and remain showing "Ariel" and "Coman" in the table
    However, when i ran the above VBA, it filters all the row and leaving empty in the table.
    The result didn't come out what i want

  4. #4
    Registered User
    Join Date
    04-23-2024
    Location
    London
    MS-Off Ver
    Microsoft 365
    Posts
    6

    Re: Help:Excel VBA to filter all 0 in the data table with formulae

    Quote Originally Posted by romperstomper View Post
    You need to add code tags to your post, not use dashes for indentation.



    I'm not sure what you mean by that. If you mean that it's hiding complete rows, then yes, that is how filters work.
    i want to filter the complete rows which the "Total AUM" have "-"
    So the VBA should be filter "Ben" & "Don" rows, and remain showing "Ariel" and "Coman" in the table
    However, when i ran the above VBA, it filters all the row and leaving empty in the table.
    The result didn't come out what i want

  5. #5
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    15,026

    Re: Help:Excel VBA to filter all 0 in the data table with formulae

    Perhaps...
    Please Login or Register  to view this content.
    Good Luck...
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the [★ Add Reputation] to left of post window...
    Also....Add a comment if you like!!!!
    And remember...Mark Thread as Solved...
    Excel Forum Rocks!!!

  6. #6
    Registered User
    Join Date
    04-23-2024
    Location
    London
    MS-Off Ver
    Microsoft 365
    Posts
    6

    Re: Help:Excel VBA to filter all 0 in the data table with formulae

    the table also got some negative numbers, i didn't show on the above table.
    But the VBA didn't work, it filter all the data.
    still thank you for the help.

  7. #7
    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
    48,986

    Re: Help:Excel VBA to filter all 0 in the data table with formulae

    Fast answers need visual help. Please read the yellow banner at the top of this page on how to attach a file and a mocked up solution.
    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


  8. #8
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    15,026

    Re: Help:Excel VBA to filter all 0 in the data table with formulae

    the table also got some negative numbers, i didn't show on the above table
    As Trevor says...Upload a sample file showing all possible entries and show expected outcome...
    I'm guessing only one small requirement in above snippet is required...
    Please Login or Register  to view this content.
    Last edited by Sintek; 06-28-2024 at 03:22 AM.

  9. #9
    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
    48,986

    Re: Help:Excel VBA to filter all 0 in the data table with formulae

    I suspect your values are actually text that look like numbers. Test with:
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Fix with Text to Columns.

+ 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. Excel Advanced Filter copied a blank table over to a new sheet instead of data
    By Wilheim in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-21-2021, 03:27 AM
  2. UserformTextbox to Filter excel data table
    By duplaly in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-28-2020, 11:58 AM
  3. How to evaluate data in a pivot table with formulae
    By opusarlo in forum Excel General
    Replies: 1
    Last Post: 11-21-2017, 01:47 PM
  4. Summarising Data with a Pivot Table and Formulae
    By andrewc in forum Excel General
    Replies: 4
    Last Post: 06-27-2014, 06:08 AM
  5. Replies: 1
    Last Post: 02-07-2014, 03:12 AM
  6. Replies: 1
    Last Post: 02-07-2014, 03:04 AM
  7. Excel formulae + drop down table
    By rubyn15 in forum Excel General
    Replies: 1
    Last Post: 02-13-2006, 05:56 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