Extracting data based on Date.

fluxcapacitr609

New Member
Joined
Feb 21, 2018
Messages
24
Im trying to to extract data and push it to another sheet based on date. The code I have works but only does column A and B when C and D has information in it also. Any help would be greatly appreciated thank you.

Sub extractDataBasedOnDate()
Dim lastrow As Long
Dim erow As Long
Dim i As Long


lastrow = Sheet2.Cells(Rows.Count, 1).End(xlUp).Row
Sheet2.Select
Range("A1").Select


For i = 2 To lastrow


mydate = Cells(i, 1)
If mydate >= "2018-02-01" And mydate <= "2018-02-29" Then
erow = Sheet4.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
Range(Cells(i, 1), Cells(i, 2)).Copy Destination:=Sheet4.Cells(erow, 1)
End If

Next i



End Sub
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Because you're now copying to col E rather than A, there is nothing in col A, hence erow doesn't change try
Code:
erow = Sheet4.Cells(Rows.Count, [COLOR=#ff0000]5[/COLOR]).End(xlUp).Offset(1, 0).Row
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top