• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

How to filter only special characters and blank using VBA

Easiest way is probably to record a macro of yourself filtering for those values. Final code will look something like this

Code:
ActiveSheet.Range("$E$1:$E$10").AutoFilter Field:=1, Criteria1:=Array("?", _
        "<", ">", "#", ""), Operator:=xlFilterValues

With the array as big as you need it to be. You'll need to define what all you mean by "special characters".
 
Code:
Sub AutoFilter()
    Dim AFRg As Range
    Dim R As Range
    Dim Stg As String
    Dim I As Integer
    Application.ScreenUpdating = False
    Set AFRg = Range("A1:A20")
    Stg = "(1234567890abcdefghijklmnopqrstuvwxyz.@)"
    For Each F In AFRg
        For I = 1 To Len(F)
            If (Len(Stg) - Len(Replace(Stg, Mid(F, I, 1), "")) <> 0) Then
                F.Font.ColorIndex = 3
                Exit For
            End If
        Next I
    Next F
    AFRg.Select
    Selection.AutoFilter
    ActiveSheet.Range("$A$1:$A$20").AutoFilter Field:=1, Criteria1:=RGB(255, 0 _
        , 0), Operator:=xlFilterFontColor
    With Selection.Font
        .ColorIndex = xlAutomatic
        .TintAndShade = 0
    End With
    Application.ScreenUpdating = True
End Sub

Mod Edit: Code tags added.
 
Last edited by a moderator:
Back
Top