View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.misc
Sean Sean is offline
external usenet poster
 
Posts: 208
Default run a macro for a selected date

Brilliant - Thanks

"Andy Brown" wrote:

"Sean" wrote in message
...
Andy,
I need to filter the spreadsheet that over 2000 rows by one date that will
select 25 enteries
I have as part of the macro a comand that says
Selection.Autofilter
Selection.Autofilter Field:=2, Criterial:-"active"
which works great but I need to filter field 9 or column j by a selected
date, which I need to choose


This line will prompt for the selected date:

FilterDate = CDate(Application.InputBox("Enter filter date"))

Over here I need to use CDate -- you may not. Then you could just add
another filter line after your Field:=2 line:

Selection.AutoFilter Field:=10, Criteria1:=FilterDate

But you may need/prefer to use an If/End if to check whether any records do
actually match FilterDate in column J -- something like:

If WorksheetFunction.CountIf(Range("J1", Range("J" & Rows.Count).End(xlUp)),
FilterDate) 0 Then
Selection.AutoFilter Field:=10, Criteria1:=FilterDate
End If

HTH,
Andy