Copy rows within date range

miyage

New member
Local time
Today, 21:15
Joined
Jan 23, 2009
Messages
7
Hi. Im a bit stuck on how to attack this problem in vba and im sure someone has a basic solution for this:

In Sheet1, I have A1: Start Date and A2: End Date
In Sheet2, is the look up sheet. Its sorted by ColumnA:
ColumnA.......ColumnB.....ColumnC...ColumnD
01/02/2008...James........20...........$200
05/02/2008...Jones .......10...........$800
06/02/2008...Mary.........30...........$900
06/02/2008...Bob...........50...........$600
07/02/2008...Jason........10...........$500
08/02/2008...Jackie........20...........$400
etc
etc

I wanted to create a button in Sheet1 that will copy the entire row of data in Sheet2 but only within the date range declared in Sheet1. and place the copied row in Sheet1 starting at position A100.

Eg.
Start Date: 05/02/2008
End Date: 07/02/2008
Click button(vba executes)
Copy all rows from lookup sheet2 within these dates and paste it in Sheet1 A100.

Any solution will be very much appreciated.
 
Hi. Im a bit stuck on how to attack this problem in vba and im sure someone has a basic solution for this:

In Sheet1, I have A1: Start Date and A2: End Date
In Sheet2, is the look up sheet. Its sorted by ColumnA:
ColumnA.......ColumnB.....ColumnC...ColumnD
01/02/2008...James........20...........$200
05/02/2008...Jones .......10...........$800
06/02/2008...Mary.........30...........$900
06/02/2008...Bob...........50...........$600
07/02/2008...Jason........10...........$500
08/02/2008...Jackie........20...........$400
etc
etc

I wanted to create a button in Sheet1 that will copy the entire row of data in Sheet2 but only within the date range declared in Sheet1. and place the copied row in Sheet1 starting at position A100.

Eg.
Start Date: 05/02/2008
End Date: 07/02/2008
Click button(vba executes)
Copy all rows from lookup sheet2 within these dates and paste it in Sheet1 A100.

Any solution will be very much appreciated.

Have a look at the Function in chergh's reply to the post in the Link below. The Op also wanted to sort by Date.

http://www.access-programmers.co.uk/...highlight=sort

I came across this post while researching a similar problem that I am having regarding sorting by State Codes.

http://www.access-programmers.co.uk/forums/showthread.php?t=168567
 
Not sure what I did in that link is really suitable for this. The easiest way to do it using a filter. Try something like this:

Code:
Sub blah()


Dim ws1 As Worksheet
Dim ws2 as Worksheet

Set ws1 = ThisWorkbook.Worksheets("Sheet1")
Set ws2 = ThisWorkbook.Worksheets("Sheet2")

ws2.Range("A1").AutoFilter Field:=1, Criteria1:=">=" & CLng(ws1.Range("A1").Value), Operator:=xlAnd, Criteria2:="<=" & CLng(ws1.Range("A2").Value)
ws2.Range("A1:A" & ws2.Range("A65536").End(xlUp).Row).Copy
ws1.Paste ws1.Range("A100")


ws2.Range("A1").AutoFilter


End Sub
 

Users who are viewing this thread

Back
Top Bottom