LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default Select rows equal to filter and highlight row

Hi,
Thanks in advance, this site has been invaluable to me!
I am trying to pick out rows after a certain date, then highlight them so
they are plainly visible when looking at the entire spreadsheet. The code
below seems to do this, but when you remove the filter, all of the rows are
highlighted. If I manually go in and sort, then highlight individual rows,
and remove the filter, it works.

Sub MarkNewPlayers()

Dim afterDate As String
Dim myDate As String
Dim wrksMain As Worksheet
Dim lastRow As String
Set wrksMain = Worksheets("PlDetails")
wrksMain.Select

' 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")
' Highlight dates after the date that is entered
If myDate = "" Or Not IsDate(myDate) Then
MsgBox "You did not enter a date.", 48, "Action cancelled."
Exit Sub
Else
afterDate = myDate
End If
' select all cells, then set filter
' Cells.Select
' Selection.AutoFilter
' find last row number
lastRow = Cells(Rows.Count, 1).End(xlUp).Row
' for testing
MsgBox lastRow
' sort spreadsheet on applicaton date - column D
ActiveSheet.Range("$A$1:$AL$" & lastRow).AutoFilter Field:=4,
Criteria1:="" & afterDate, Operator:=xlAnd
With ActiveWorkbook.Worksheets("PlDetails").AutoFilter. Sort
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
' set selection to column D row 2
Range("D2").Select
' loop to pick rows to highlight
Do
If ActiveCell.Value = afterDate Then
' Set "RowNum" to the active row, then select row
rowNum = ActiveCell.Row
Range("A" & rowNum & ":AL" & rowNum).Select
' Green Background Fill
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 5296274
.TintAndShade = 0
.PatternTintAndShade = 0
End With
' ActiveWindow.DisplayGridlines = True

' Below changes active cell back to RowNum, Column 3
ActiveCell.Offset(1, 3).Select
' Else moves from active cell down 1 row
Else: ActiveCell.Offset(1, 0).Select
End If
Loop Until IsEmpty(ActiveCell)

ActiveSheet.Range("$A$1:$AL$" & lastRow).AutoFilter Field:=4

End Sub
--
JohnM
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
highlight row if cell value equal zero amanda Excel Programming 2 January 9th 09 06:53 PM
Filter and select the upmost rows Ranjit kurian Excel Programming 2 April 28th 08 05:26 PM
Highlight the lowest number - only if it does not equal another va JJ2356 Excel Discussion (Misc queries) 6 April 17th 08 10:10 PM
Excel data filter collapses rows even after I select show all!?!?!? [email protected] Excel Discussion (Misc queries) 4 January 9th 07 12:42 PM
Filter/Select multiple rows a_moron Excel Discussion (Misc queries) 5 January 20th 06 02:41 PM


All times are GMT +1. The time now is 02:29 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"