VBA Code - Filter only on numbers

OilEconomist

Active Member
Joined
Dec 26, 2016
Messages
421
Office Version
  1. 2019
Platform
  1. Windows
Update, title should read special characters and numbers. Apologies.

Thanks in advance for any recommendations. I'm looking for VBA code that will filter on anything that is not a word. The entry will be one entry (i.e. not a sentence). I am looking to filter on anything that is not a word. For example, I want to filter on anything that begins with a number or a character. So like the following:
(hello
99
99,000
?

Here is the start of the code. I put a ? in the criteria as that's what I'm trying to figure out.

VBA Code:
Sub Test()
Sheets("Sheet1").Activate
Range("A8:G8").AutoFilter Field:=5, Criteria1:="?"
Range("A9:G1000").SpecialCells(xlCellTypeVisible).Delete
ActiveSheet.ShowAllData
End Sub
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Try this way...original code modified from @Sahadev Reddy
VBA Code:
Sub MM1()
    Dim R As Range, c As Range, rng As String, I As Integer
    Application.ScreenUpdating = False
    rng = "(1234567890!().$&)" ' add characters as required
    For Each c In Range("A9:G1000")
        For I = 1 To Len(c)
            If (Len(rng) - Len(Replace(rng, Mid(c, I, 1), "")) <> 0) Then
                c.Font.ColorIndex = 3
                Exit For
            End If
        Next I
    Next c
   With Range("A8:G1000")
   .AutoFilter
    .AutoFilter Field:=1, Criteria1:=RGB(255, 0, 0), Operator:=xlFilterFontColor
    With Range("A8:G1000").Font
        .ColorIndex = xlAutomatic
        .TintAndShade = 0
    End With
 .Range("A9:G1000").SpecialCells(xlCellTypeVisible).Delete 'this will do individual cells...if you want entire row you will need Entirerow.delete
 End With
 Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,592
Messages
6,120,433
Members
448,961
Latest member
nzskater

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top