View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
OssieMac OssieMac is offline
external usenet poster
 
Posts: 2,510
Default Select rows equal to filter and highlight row

Hi again John,

I was short on time earlier but I have now had a closer look at your code
and if I am interpreting correctly what you want to do then I think it should
be more like the following. Note that I have removed existing filters and
cleared any existing interior formatting before setting the filter again and
setting the interior color of the visible cells.

Sub MarkNewPlayers()

Dim afterDate As String
Dim myDate As String
Dim wrksMain As Worksheet
Dim lastRow As String
Dim rngFiltered As Range

Set wrksMain = Worksheets("PlDetails")

' Message Box opens to enter the Date to use in the file name
myDate = InputBox _
("Please enter your date in mm/dd/yyyy format:", _
"What date do you want to enter?", "mm/dd/yyyy")

If myDate = "" Or Not IsDate(myDate) Then
MsgBox "You did not enter a date.", 48, "Action cancelled."
Exit Sub
Else
afterDate = myDate
End If

lastRow = Cells(Rows.Count, 1).End(xlUp).Row

'Clear existing filters (if any)
With wrksMain
If .AutoFilterMode Then
If .FilterMode Then
.ShowAllData
End If
End If
End With

'Clear existing interior colors
With wrksMain.Range("$A$1:$AL$" & lastRow).Interior
.Pattern = xlNone
.TintAndShade = 0
.PatternTintAndShade = 0
End With

'Set AutoFilter on Field 4
wrksMain.Range("$A$1:$AL$" & lastRow) _
.AutoFilter Field:=4, _
Criteria1:="" & afterDate

'Set rngFiltered to just the visible cells
With wrksMain.AutoFilter.Range
Set rngFiltered = .Offset(1, 0) _
.Resize(.Rows.Count - 1, .Columns.Count) _
.SpecialCells(xlCellTypeVisible)
End With

'Set interior color of visible cells
With rngFiltered.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 5296274
.TintAndShade = 0
.PatternTintAndShade = 0
End With

End Sub

--
Regards,

OssieMac