Select all rows in a date range

T

thomasDrew

I have two dates - a start date in A1 and an end date in B1. I want to select
all rows containing dates in that range, copy them and paste to a new
worksheet within the same workbook. The date column is sorted early to late
dates.
 
B

Bob Phillips

Public Sub Test()
Dim StartRow As Long
Dim EndRow As Long

With ActiveSheet

On Error Resume Next
StartRow = Application.Match(CLng(.Range("A1").Value),
..Range("rngDates"), 0)
On Error GoTo 0

If StartRow = 0 Then

MsgBox "Start date not matched"
Exit Sub
End If

On Error Resume Next
EndRow = Application.Match(CLng(.Range("B1").Value),
..Range("rngDates"), 0)
On Error GoTo 0

If EndRow = 0 Then

MsgBox "End date not matched"
Exit Sub
End If

.Range("rngDates").Cells(StartRow, 1).Resize(EndRow - StartRow +
1).Copy _
Worksheets("Sheet2").Range("A1")
End With
End Sub

--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my addy)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top