ExcelGirl1988
New Member
- Joined
- Mar 27, 2017
- Messages
- 44
Hi,
I have been working on this code for a while and I have finally figured most of it out but some of it still is not working how I need it to. The code is going to be used to search for a date (input by the user) across all worksheets and then the data in that row will be copied onto the summary worksheet but I cannot figure out how to get all the row copied over, only the first 2 cells are copied, not all cells with data in the row.
The code I am using is:
I think the troublesome part of the code is:
Could anyone offer any suggestions? Thank you
I have been working on this code for a while and I have finally figured most of it out but some of it still is not working how I need it to. The code is going to be used to search for a date (input by the user) across all worksheets and then the data in that row will be copied onto the summary worksheet but I cannot figure out how to get all the row copied over, only the first 2 cells are copied, not all cells with data in the row.
The code I am using is:
Code:
Sub ExtractDataBasedOnDate()
Dim LastRow As Long, erow As Long, i As Long
Dim myDate As Date, StartDate As Date, EndDate As Date
Dim ws As Worksheet
Dim starting_ws As Worksheet
Set starting_ws = ActiveSheet
Application.ScreenUpdating = False
LastRow = Sheet2.Cells(Rows.Count, 1).End(xlUp).Row
StartDate = Sheets("Home").Range("D3").Value
EndDate = Sheets("Home").Range("D4").Value
For Each ws In ThisWorkbook.Worksheets
If ws.Name <> "Summary" Then
ws.Activate
Application.CutCopyMode = False
For i = 2 To LastRow
myDate = Cells(i, 2)
If myDate >= StartDate And myDate <= EndDate Then
erow = Sheets("Summary").Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
Range(Cells(i, 1), Cells(i, 2)).Copy Destination:=Sheets("Summary").Cells(erow, 1)
Application.CutCopyMode = False
End If
Next i
End If
Next ws
starting_ws.Activate
Application.ScreenUpdating = True
End Sub
I think the troublesome part of the code is:
Code:
Range(Cells(i, 1), Cells(i, 2)).Copy
Could anyone offer any suggestions? Thank you