'============================================
'- Update August 2007
'- FIND RECORDS FROM A RANGE OF DATES IN A DATA TABLE
'- AND COPY SELECTED COLUMNS INTO A SUMMARY SHEET
'- change "DataSheet" to lookup sheet name
'- change "SummarySheet" to summary sheet name
'_ change ranges as appropriate
'- Original Code: Brian Baulsom February 2005
'- Edits: Brian Wethington August 2007
'- Edits: Chris Thoma August 2007
'=============================================
'-
Sub FindRecords()
Dim FromSheet As Worksheet
Dim FromRow As Long
Dim ToSheet As Worksheet
Dim ToRow As Long
Dim FindThis As Date
Dim FoundCell As Object
Dim Wbfrom As Workbook
Dim FirstAddress As String
Dim FindThis2 As Date
Dim RngLen As Long
Dim x As Long
'---------------------------------------------------
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
'---------------------------------------------------
'- get user inputs
FindThis = InputBox("Please enter start date: ")
FindThis2 = InputBox("Please enter end date: ")
RngLen = Abs(FindThis2 - FindThis)
If FindThis2 < FindThis Then FindThis = FindThis2
'---------------------------------------------------
Set Wbfrom = Workbooks.Open(Filename:="DataSheetFile)")
Set FromSheet = Wbfrom.Worksheets("DataSheet")
Set ToSheet = ThisWorkbook.Worksheets("SummarySheet")
ToRow = 2
'---------------------------------------------------
'- clear summary for new data
ToSheet.Cells.Range("A2:BE5000").Clear
'---------------------------------------------------
' FIND DATA
For x = 0 To RngLen
With FromSheet.Range("D2:D5000")
Set FoundCell = .Find(FindThis + x, LookIn:=xlFormulas)
If Not FoundCell Is Nothing Then
FirstAddress = FoundCell.Address
'------------------------------------------
'- copy selected columns of data to report
Do
FromRow = FoundCell.Row
FromSheet.Cells(FromRow, 1).Copy ToSheet.Cells(ToRow, 1)
FromSheet.Cells(FromRow, 2).Copy ToSheet.Cells(ToRow, 2)
FromSheet.Cells(FromRow, 4).Copy ToSheet.Cells(ToRow, 3)
FromSheet.Cells(FromRow, 6).Copy ToSheet.Cells(ToRow, 4)
FromSheet.Cells(FromRow, 7).Copy ToSheet.Cells(ToRow, 5)
FromSheet.Cells(FromRow, 8).Copy ToSheet.Cells(ToRow, 6)
FromSheet.Cells(FromRow, 10).Copy ToSheet.Cells(ToRow, 7)
FromSheet.Cells(FromRow, 11).Copy ToSheet.Cells(ToRow, 8)
FromSheet.Cells(FromRow, 13).Copy ToSheet.Cells(ToRow, 9)
FromSheet.Cells(FromRow, 19).Copy ToSheet.Cells(ToRow, 10)
FromSheet.Cells(FromRow, 28).Copy ToSheet.Cells(ToRow, 11)
ToRow = ToRow + 1
Set FoundCell = .FindNext(FoundCell)
Loop While Not FoundCell Is Nothing And _
FoundCell.Address <> FirstAddress
'------------------------------------------
End If
End With
Next x
Application.Workbooks("DataSheetFile").Close SaveChanges:=False
MsgBox ("Done.")
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
End Sub