Searching A Worksheet


Posted by Roy Brunt on August 19, 2001 9:57 AM

Can anyone help me out. I am after code which will allow me to input 2 dates via input boxes and then pull the relevant info from my spreadsheet....ie the info that only has these dates, my dates are in column A.

I then want to copy the relevant data to another spreadsheet. Any help would be greatly appreciated.

Thanks
Roy



Posted by Robb on August 20, 2001 4:46 AM

Roy

You'll have to adjust to your ranges, but this should do what you want:

Sub RCopy()
Dim D1 As Date, D2 As Date, R2 As Integer, copR As String
D1 = InputBox("Enter a date")
D2 = InputBox("Enter a second date")
R2 = 2
copR = "A" & CStr(R2)
Worksheets("Sheet1").Activate
For Each r In Worksheets("sheet1").UsedRange.Rows
n = r.Row
If Cells(n, 1) = D1 Or Cells(n, 1) = D2 Then
r.Copy Destination:=Worksheets("Sheet2").Range(copR)
R2 = R2 + 1
copR = "A" & CStr(R2)
Else
End If
Next r


End Sub


Any help?

Regards