View Single Post
 
Old 07-12-2015, 05:33 PM
charlesdh charlesdh is offline Windows 7 32bit Office 2010 32bit
Expert
 
Join Date: Apr 2014
Location: Mississippi
Posts: 382
charlesdh is on a distinguished road
Default

HI,

If the word "fitness" is in column "B" and there are no "Blanks" in column "B".

This code may work. Not sure if the size of your data will effect it.
Also as mentioned supply a copy of your work.

Code:
Sub Test_Filter()
Dim i As Long
Dim VisRng As Range
Dim Myval As Long
Dim lrow As Long
'' set filter ''
lrow = Sheets("Sheet1").Range("B65536").End(xlUp).Row '' rename to your sheet
Sheets("Before").Range("A1:f1").Select
        Selection.AutoFilter
        With Selection
            .AutoFilter Field:=2, Criteria1:="fitness"  '' this set the filtered data for the value
        End With
            With Worksheets("Before").AutoFilter.Range
                Set VisRng = .Resize(.Rows.Count - 1, 1).Offset(1, 0) _
                    .Cells.SpecialCells(xlCellTypeVisible)
            '' make sure you have more than 1 row  ''
                Myval = .Range("B2:B" & lrow).SpecialCells(xlCellTypeVisible).Count
                If Myval >= "2" Then
                    Range(Cells(VisRng.Offset(, 0).Row, 1), Cells(Range("B65536").End(xlUp).Row, 8)).EntireRow.Delete
                End If
            End With

        Selection.AutoFilter
End Sub
Reply With Quote