Copying data from a table based on two date values

K

Kirsty

Hi,

I have a table in one worksheet. I want to select a range of data from that
table. The range is between two dates, which are in cells on a second
worksheet.
I then want to copy and paste the selected data to a worksheet utilising a
macro.

How is this done
 
A

aamerrasheed via OfficeKB.com

Hi,

You can do it like this.
Sheet 1 contains all your data with date in first column.
On Sheet2, cell A1 has "start date" and A2 has "end date".
When you run this macro, all data between the two dates will be copied to
sheet3.

Sub daterange()
j = 1
For i = 1 To Sheet1.UsedRange.Rows.Count
If (Sheet1.Cells(i, 1) >= Sheet2.Cells(1, 1) And Sheet1.Cells(i, 1)
<= Sheet2.Cells(2, 1)) Then
Sheet1.Rows(i).Copy Sheet3.Rows(j)
j = j + 1
End If
Next i
End Sub

I hope that this will serve your purpose.

Thanks,
Aamer
 
Top