ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Copying data from a table based on two date values (https://www.excelbanter.com/excel-programming/422143-copying-data-table-based-two-date-values.html)

Kirsty

Copying data from a table based on two date values
 
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

aamerrasheed via OfficeKB.com

Copying data from a table based on two date values
 
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

Kirsty wrote:
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


--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200901/1



All times are GMT +1. The time now is 07:28 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com