Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Filtering inputted dates using criteria

I'm looking for a way to have a macro use the a filter to filter out
dates using the greater/less than or equal to.

The date needs to be changeable, so I have the user inputing the dates,
but can't figure out how to get the advanced filter to work when
inputing the date manually (via InputBox).

This is as far as my macro goes for now, because I'm stuck:

Sub SingleTrainingRecord()
' SingleTrainingRecord Macro
Sheets("All Years").Select
Dim Message, Title, Employee, Trainee, ColNo, StartDate, StopDate

Message = "Enter employee's name" ' Set prompt.
Title = "Select employee" ' Set title.
' Display message, title, and default value.
Beep
Employee = InputBox(Message, Title)
If Employee = "" Then Exit Sub

StartDate = InputBox("Enter the Start Date:")
If StartDate = "" Then End
StopDate = InputBox("Enter the Stop Date:")
If StopDate = "" Then End

On Error GoTo errHandler

Cells.Find(What:=Employee, After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext,
_
MatchCase:=False).Activate

Trainee = ActiveCell.Value
ColNo = ActiveCell.Column

Selection.Copy
Sheets("Extract").Select
Rows("1:1").RowHeight = 30
ActiveSheet.Paste
Sheets("All Years").Select
Columns(ColNo).Select
Application.CutCopyMode = False
Selection.AutoFilter
Selection.AutoFilter Field:=1, Criteria1:="=startdate" and
criteria2:="<=stopdate"
Columns("A:F").Select
Selection.Copy
Sheets("Extract").Select
Range("A2").Select
ActiveSheet.Paste
Range("A1").Select
Sheets("All Years").Select
Application.CutCopyMode = False
ActiveSheet.ShowAllData
Selection.AutoFilter
Range("A1").Select
Sheets("Extract").Select

Exit Sub

errHandler:
If Err.Number = 91 Then
Wrap$ = Chr$(10) + Chr$(13)
MsgBox "Excel is having trouble finding the information you
requested." & Wrap$ & Wrap$ & "Please ensure that the spreadsheet is
open and that the trainee exists." & Wrap$ & Wrap$ & Wrap$ & "The name
you typed was '" & Employee & "'. Please ensure that this is correct
and then try again.", vbCritical, "Failed to find Trainee"
Exit Sub
Else
If MsgBox(Err.Number & " - " & Err.Description, vbOKCancel) =
vbCancel Then Exit Sub
Resume
End If

End Sub

Any ideas?

Reply
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
MAX value but with two comparison filtering criteria Struggling in Sheffield[_2_] Excel Discussion (Misc queries) 5 February 24th 10 07:04 PM
Filtering with multiple criteria fgwiii[_2_] Excel Discussion (Misc queries) 1 June 9th 09 04:52 PM
Filtering by criteria within PV in Excel. Sardonic Excel Discussion (Misc queries) 0 December 4th 07 02:57 PM
How do I ensure dates inputted are during the work week? Jim Johnson Excel Worksheet Functions 3 October 29th 04 08:25 AM
Advanced Filtering criteria FinChase Excel Programming 1 October 21st 04 06:58 PM


All times are GMT +1. The time now is 05:55 AM.

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

About Us

"It's about Microsoft Excel"