Im looking for a VBA Code which essentially counts the times the macro is run and resets the program. The macro currently copies an array of data and pastes it onto a seperate sheet. Each week the data will change so the macro will be run every week to get that weeks worth of data (the data is pasted directly below the last cell used in the previous weeks paste). Ideally, id like to partition the data to every 4 weeks and i beleive the best way to do this would be a count and reset function (if theres a better way then by all means)! Ideally, the code would also every four weeks start a new sheet for the data to be copied and name the previous one something like "Week 1-4". So after a few months id have an active sheet where the data for that 4-week period is running and a log of previous weeks names week 1-4, week 5-8, ... and so on
The closest ive got so far is assigning a cell which +1 everytime the macro is run and an IF function stating to reset after 4. But i have no idea how to go about the new sheet and naming thing.
Sub Historization()
workbookname = ActiveWorkbook.Name
'If Range("P3").Value >= 4 Then
'add new sheet in
'For Each ws In ThisWorkbook.Worksheets
'code in here
'Next
' loop through all worksheets
'worksheetname = ActiveSheet.Name
'Else
'End If
Workbooks("Historized_CAS_RK_Control.xlsm").Worksheets("Query").Activate
Range("A1").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select
Workbooks(workbookname).Select
Worksheets(worksheetname).Activate
Range("A1").Select
ActiveCell.End(xlDown).Select
ActiveSheet.Paste
thecount = Range("P3").Value
thecount = thecount + 1
Range("P3").Value = thecount
End Sub