Hi all,
I have created the below macro that will check the dates in column 8 on sheet1. It will then copy the row and paste the data onto sheet2 if the date is less than or equal to cell "K1". The macro is working perfectly but i'm struggling to tell excel to delete the the row after it has been copied.
This is what i've done so far;
I have created the below macro that will check the dates in column 8 on sheet1. It will then copy the row and paste the data onto sheet2 if the date is less than or equal to cell "K1". The macro is working perfectly but i'm struggling to tell excel to delete the the row after it has been copied.
This is what i've done so far;
Code:
Sub Import_data()
a = Worksheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row
Dim sh1 As Worksheet
Set sh1 = Worksheets("sheet1")
Dim sh2 As Worksheet
Set sh2 = Worksheets("sheet2")
For i = 2 To a
If sh1.Cells(i, 8).Value <= sh2.Range("k1").Value Then
sh1.Rows(i).Cut
sh2.Activate
b = sh2.Cells(Rows.Count, 1).End(xlUp).Row
sh2.Cells(b + 1, 1).Select
ActiveSheet.Paste
sh1.Activate
End If
Next
Application.CutCopyMode = False
sh1.Activate
ThisWorkbook.Worksheets("sheet1").Cells(1, 1).Select
sh2.Activate
End Sub
Last edited: