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
Bookmarks