"Daveo" <writetodaveo@gmail.com> wrote in message
news:1127273931.540930.127830@g14g2000cwa.googlegroups.com...
> Hi Biff,
>
> The number of records increases at around 50 per day, but I'll clear
> out ones older than 3 months old so let's say there wont be more than
> 5000 records. I'll probably only be looking to return about 1500 at the
> very most at a time.
>
> The data table is in Sheet1 from A2:AQ500 to start with but the 500
> part will obvioulsy change as time goes on.
>
> Lets say the lower and upper bounds are in cells A1 and B1
> respectively.
>
> I'd want to extract to Sheet2 all the data in columns A:AQ that fall
> within the date range of cells A1 and B1.
>
> What's the best way?
>
> Many thanks - David
I suppose you don't have Blanks on your Date column.
If it is not the case, please let me know.
Define StartCell, TargetCell, ColNum, LowerDate, UpperDate
-----------------------------------------------------
Sub Button36_Click()
Dim StartCell As Range, TargetCell As Range
Dim ColNum As Byte, LowerDate As Range, UpperDate As Range
Dim i, j As Long, k As Long
'User Definitions
'------------------------------
Set StartCell = Sheets("Sheet2").[A230]
Set TargetCell = Sheets("Sheet10").[A1]
ColNum = 4
Set LowerDate = [A228]
Set UpperDate = [A229]
'------------------------------
On Error GoTo ErrHandler
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
For Each i In Range(StartCell, StartCell.End(xlDown))
If i >= LowerDate And i <= UpperDate Then
For k = 0 To ColNum - 1
TargetCell.Offset(j, k) = i.Offset(0, k)
Next
j = j + 1
End If
Next
ErrHandler:
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub
------------------------------------
Bruno
Bookmarks