I have a workbook "DATABASE" with 5 sheets, I am trying to let my code copy contents of all 4 sheets and paste it to one master sheet "ARCHIVE" to be all together compiled.
I want each time the code runs, to clear contents in ARCHIVE and then paste copied values from other sheets. So that there will be no duplication every time is runs.
the code works fine before the clear thing, but when I add activesheets.cells.clearcontents
or sheets("ARCHIVE").cells.clearcontents
after the sheets("ARCHIVE").activate
it doesn't work.
can someone help me where exactly should I put the clear contents code for ARCHIVE sheet before pasting? and if I should declare something before?
I have put here the code while its working properly without the clear thing:
Sub CopyToMaster()
ShtCount = ActiveWorkbook.Sheets.Count
For I = 2 To ShtCount
Worksheets(I).Activate
LastRow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row
Range("a2:N" & LastRow).Select
Selection.Copy
Sheets("ARCHIVE").Activate
LastRow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Select
'Required after first paste to shift active cell down one
Do While Not IsEmpty(ActiveCell)
ActiveCell.Offset(1, 0).Select
Loop
ActiveCell.Offset(0, 0).Select
Selection.PasteSpecial
ActiveWorkbook.Save
Next I
End Sub
Sub tensecondstimer()
Application.OnTime Now + TimeValue("00:00:10"), "CopyToMaster"
End Sub