Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 290
Default Find by date range

Hi all,

I am trying to modify another sub of mine so that instead of searching
by one criteria it searches by two date ranges input on the form and
brings back a list of everything between those dates. The part that is
not working is where I choose the criteria, nothing I have tried seems
to work, I tried using = date1.value and <=date2.value but that wont
work, I will post the full sub below and perhaps somebody could help?
Maybe I should do it a whole differant way instead of trying to modify
what I already had, taking the easy way out never works for
me!...........



Private Sub CommandButton1_Click()

Sheets("sheet1").Select
Dim rng As Range

Set rng = Range("A1:I" & Range("a65536").End(xlUp).Row)
rng.Select

Range("A1").End(xlDown).Offset(1, 0).Select
ActiveCell.Select

Columns("d:d").AutoFilter Field:=4, _
Criteria1:=Date1.Value, Criteria2:=Date2.Value

Select Case MsgBox("Print?", vbYesNo)

Case vbYes
Sheet1.Activate
rng.Select

Selection.PrintOut Copies:=1, Collate:=True

Selection.AutoFilter
UserForm1.Show
regTrail.Value = ""
regTrail.SetFocus
Exit Sub

Case vbNo
Selection.AutoFilter
UserForm1.Show
regTrail.Value = ""
regTrail.SetFocus

Exit Sub
End Select
Sheets("sheet1").Select

End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,163
Default Find by date range

Try the following (assuming Date1 is the start date for the date range and
Date2 is the end):
Columns("d:d").AutoFilter Field:=4, _
Criteria1:="=" & Date1.Value, Criteria2:= "<=" & Date2.Value

Note that the dates in Date1 and Date2 must be actual date values, not text.
If you have a text representation of the date, then use
DateValue(Date1.Value) to convert it to a serial date number.
--
- K Dales


"Duncan" wrote:

Hi all,

I am trying to modify another sub of mine so that instead of searching
by one criteria it searches by two date ranges input on the form and
brings back a list of everything between those dates. The part that is
not working is where I choose the criteria, nothing I have tried seems
to work, I tried using = date1.value and <=date2.value but that wont
work, I will post the full sub below and perhaps somebody could help?
Maybe I should do it a whole differant way instead of trying to modify
what I already had, taking the easy way out never works for
me!...........



Private Sub CommandButton1_Click()

Sheets("sheet1").Select
Dim rng As Range

Set rng = Range("A1:I" & Range("a65536").End(xlUp).Row)
rng.Select

Range("A1").End(xlDown).Offset(1, 0).Select
ActiveCell.Select

Columns("d:d").AutoFilter Field:=4, _
Criteria1:=Date1.Value, Criteria2:=Date2.Value

Select Case MsgBox("Print?", vbYesNo)

Case vbYes
Sheet1.Activate
rng.Select

Selection.PrintOut Copies:=1, Collate:=True

Selection.AutoFilter
UserForm1.Show
regTrail.Value = ""
regTrail.SetFocus
Exit Sub

Case vbNo
Selection.AutoFilter
UserForm1.Show
regTrail.Value = ""
regTrail.SetFocus

Exit Sub
End Select
Sheets("sheet1").Select

End Sub


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
Find product from date range [email protected] Excel Worksheet Functions 5 October 16th 09 07:46 PM
Find Last cell in Range when range is date format default105 Excel Discussion (Misc queries) 5 July 7th 09 03:11 PM
Find within Date Range MrRJ Excel Discussion (Misc queries) 4 November 24th 08 06:56 PM
How to find date in a range? hideki[_21_] Excel Programming 1 November 26th 05 04:16 AM
Find date and copy range based on that date avzundert Excel Programming 2 November 25th 04 10:31 AM


All times are GMT +1. The time now is 02:02 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"