Excel 365 VBA Pull data with DateRange and Copy to Table

DBaker7777

Board Regular
Joined
Feb 3, 2009
Messages
53
Office Version
  1. 365
  2. 2016
I have this code so far, but this only copies and adds the data to new rows for the range. I want to insert the data from the Data Entry sheet from the user defined date range to a table on the Report sheet, but have the table clear before inserting the new data.

VBA Code:
Sub Reporting()
Dim lastrow as Long, i as long, erow as Long
Dim sheetdate as Date, startdate As Date, enddate as Date
lastrow = Worksheets("DataEntry").usedrange.rows.count
startdate = Inputbox ("Enter start date as mm-dd-yyyy","Enter start date")
enddate = Inputbox ("Enter the end date as mm-dd-yyyy","Enter end date")
For i = 2 To lastrow
sheetdate = Cells(i, 1)
If sheetdate >= startdate and sheetdate <= enddate Then
erow = Worksheets("Report").UsedRange.Rows.Count + 1
Range (Cells(i,1), Cells(i, 5)).Copy Destination:=Sheets("Report").cells(erow, 1)
End If
Next I
End Sub
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.

Forum statistics

Threads
1,214,986
Messages
6,122,611
Members
449,090
Latest member
vivek chauhan

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