Select all rows in a date range

  • Thread starter Thread starter thomasDrew
  • Start date Start date
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.
 
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)
 
Back
Top