Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Start and end criteria macro

Does anyone know how to create a macro that when specific criteria i
input to input boxes it searches and copys data between the two.

i.e. if i had data filed by dates and i wanted to pull information fro
the sheet to copy to a report. I would enter the start date and the
the end date. The end date must be last end date if there a tw
enteries for the same date. the info would then be selected for cop
and paste.

Regards
Pau

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,979
Default Start and end criteria macro

You can use an AutoFilter to filter for data in a date range, then copy
the visible cells to a different sheet. The following macro was adapted
from code posted by Tom Ogilvy:
http://www.contextures.com/xlautofilter03.html#Copy

'=====================================
Sub CopyDateRange()
Dim rng As Range
Dim rng2 As Range
Dim strStart As String
Dim strEnd As String
strStart = Application.InputBox("Start Date")
strEnd = Application.InputBox("End Date")

Selection.AutoFilter Field:=1, _
Criteria1:="=" & CDate(strStart), Operator:=xlAnd, _
Criteria2:="<=" & CDate(strEnd)

With ActiveSheet.AutoFilter.Range
On Error Resume Next
Set rng2 = .SpecialCells(xlCellTypeVisible)
On Error GoTo 0
End With
If rng2 Is Nothing Then
MsgBox "No dates in that range"
Else
Worksheets("Sheet2").Cells.Clear
Set rng = ActiveSheet.AutoFilter.Range
rng.Copy Destination:=Worksheets("Sheet2").Range("A1")
End If
ActiveSheet.ShowAllData
End Sub
'==========================================

xsilverx wrote:
Does anyone know how to create a macro that when specific criteria is
input to input boxes it searches and copys data between the two.

i.e. if i had data filed by dates and i wanted to pull information from
the sheet to copy to a report. I would enter the start date and then
the end date. The end date must be last end date if there a two
enteries for the same date. the info would then be selected for copy
and paste.


--
Debra Dalgleish
Excel FAQ, Tips & Book List
http://www.contextures.com/tiptech.html

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Start and end criteria macro

Thank you for explainging the above.

I have adapted part of the suggested VBA for my project and only use
the part:

Dim strStart As String
Dim strEnd As String
strStart = Application.InputBox("Start Date, (dd/mm/yyyy)")
strEnd = Application.InputBox("End Date, (dd/mm/yyyy)")

Selection.AutoFilter Field:=1, _
Criteria1:="=" & CDate(strStart), Operator:=xlAnd, _
Criteria2:="<=" & CDate(strEnd)

It all works ok but after the filter there is no displayed data. I have
tried the record macro function and adapted in parts for input but this
does not resolve the problem.

This problem does not occur when the custom filter is used manually.

I do require the macro as the spreadsheet is used by a number of people
with different levels of IT knowlege.

Regards
Paul


---
Message posted from http://www.ExcelForum.com/

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,979
Default Start and end criteria macro

Try converting the dates to serial numbers:

Selection.AutoFilter Field:=1, _
Criteria1:="=" & CLng(CDate(strStart)), Operator:=xlAnd, _
Criteria2:="<=" & CLng(CDate(strEnd))


xsilverx wrote:
Thank you for explainging the above.

I have adapted part of the suggested VBA for my project and only use
the part:

Dim strStart As String
Dim strEnd As String
strStart = Application.InputBox("Start Date, (dd/mm/yyyy)")
strEnd = Application.InputBox("End Date, (dd/mm/yyyy)")

Selection.AutoFilter Field:=1, _
Criteria1:="=" & CDate(strStart), Operator:=xlAnd, _
Criteria2:="<=" & CDate(strEnd)

It all works ok but after the filter there is no displayed data. I have
tried the record macro function and adapted in parts for input but this
does not resolve the problem.

This problem does not occur when the custom filter is used manually.

I do require the macro as the spreadsheet is used by a number of people
with different levels of IT knowlege.



--
Debra Dalgleish
Excel FAQ, Tips & Book List
http://www.contextures.com/tiptech.html

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Start and end criteria macro

Thank you very much Debra! It is now working fine!!

:D :D :

--
Message posted from http://www.ExcelForum.com

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
Need formula and not sure where to start! Matching criteria. Greg[_4_] Excel Worksheet Functions 5 August 21st 08 06:21 AM
Sub Macro vrs Function Macro Auto Start Pat Excel Discussion (Misc queries) 7 June 6th 07 09:53 PM
How to start a Macro Rick_T Excel Discussion (Misc queries) 1 December 28th 06 04:50 PM
I need a criteria expression to not include records that start wit Steve A Excel Worksheet Functions 2 August 16th 06 07:57 PM
Start Macro / Stop Macro / Restart Macro Pete[_13_] Excel Programming 2 November 21st 03 05:04 PM


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

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"