I have an Excel workbook that has ~15 sheets. I'm looking for a way to copy rows to a new sheet based on the date range in column K.
Example:
Sheet 1: Date range (1/1/15 - 1/1/18) -> Copy all rows within time range to Sheet 4
Sheet 2: Date range (1/1/15 - 1/1/18) -> Copy all rows within time range to Sheet 5
Sheet 3: Date range (1/1/15 - 1/1/18) -> Copy all rows within time range to Sheet 6
etc.
Code which does the job one sheet at a time, but I would like it to work on one go:
Sub Date_Sample() Application.ScreenUpdating = False On Error GoTo M Dim i As Long Dim ans As Date Dim anss As Date Dim Lastrow As Long Dim Lastrowa As Long ans = InputBox("Start Date Is") anss = InputBox("End Date Is") Lastrowa = Sheets("Sheet1").Cells(Rows.Count, "K").End(xlUp).Row Lastrowb = Sheets("Sheet4").Cells(Rows.Count, "K").End(xlUp).Row + 1 For i = 1 To Lastrowa If Cells(i, "K").Value >= ans And Cells(i, "K").Value <= anss Then Rows(i).Copy Destination:=Sheets("Sheet4").Rows(Lastrowb) Lastrowb = Lastrowb + 1 Rows(i).EntireRow.Delete i = i - 1 End If Next i Application.ScreenUpdating = True Exit Sub M: MsgBox "Wrong Date" Application.ScreenUpdating = True End Sub I tried adding another For statement for the other sheets but it did not work.