Not bad for a beginner
Biggest problem is that the datedif function is wrongly formatted it is not a valid function this way and unneeded to what you need.
some comments to the changes.
errors:
- lastrow is not existing variable you will need to give it a value yourself
I added line LastRow = Sheets("Data").Range("E"& Rows.count).End(xlUp).Row
you will have to change the "Data" to the actual sheetname of the sheet with the data that needs archiving
- Range( i& rows.count) will not give you a valid range, rows count will be 1048756 i will be 1 to lastrow so also a rownumber so it will evaluate int Range(11048756) which is not valid.
so either use Range("A"& Rows.count) or Cells(Rows.count,1) as startcel to find the last row the archivesheet
- as a guideline: be precize in loops most likely you will have an headerrow that you dont want be copied, so start at row 2 for the loop to avoid errors with multiple headers in your archive
- as a guideline: dont use worksheetfunctions in VBA unless you are pasting them into a cell as a function as part of the VBA project. 99 out of 100 times there is a VBA alternative code available that is faster
- as a guideline: avoid cutting or copying entire rows (or columns) , that copies 16384 cells most of which are empty. Only copy the actual used data area there are several ways to do that I picked .resize for this project. you will need to change the 10 to the actual number of columns in your data.
___________
sidenote:
proper format of function is
DATEDIF(Cells(i, 5), Date, "d")
Bookmarks