sandcounter
Technical User
I have a workbook used for job reporting each day. Each day uses a new worksheet and formulas in each sheet reference the day before for a rolling total. Each day, the user has to copy the last work sheet, and perform a "replace all" to change formula code to reference the day before instead of two days before. For example:
on "Day 3" the user copies the "Day 2" sheet and replaces all 'Day 1'! with 'Day 2'! and then name the sheet "Day 3"
I am trying to automate the process using a vba macro, but I am running into trouble making the code smart enough to replace the 'Day #'! with 'Day @'! where # = Today - 2 and @ = Today - 1.
Any help would be appriciated, See my code below:
Sub NewReport()
'Copy sheet
ActiveSheet.Select
ActiveSheet.Copy After:=ActiveSheet
'Replace Cells names
Cells.Replace What:="'" & Sheet1.Name & "'!", Replacement:="'" & Sheet2.Name & "'!", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
'Name Sheet
ActiveSheet.Name = "Day " & Sheet1.Name
End Sub
on "Day 3" the user copies the "Day 2" sheet and replaces all 'Day 1'! with 'Day 2'! and then name the sheet "Day 3"
I am trying to automate the process using a vba macro, but I am running into trouble making the code smart enough to replace the 'Day #'! with 'Day @'! where # = Today - 2 and @ = Today - 1.
Any help would be appriciated, See my code below:
Sub NewReport()
'Copy sheet
ActiveSheet.Select
ActiveSheet.Copy After:=ActiveSheet
'Replace Cells names
Cells.Replace What:="'" & Sheet1.Name & "'!", Replacement:="'" & Sheet2.Name & "'!", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
'Name Sheet
ActiveSheet.Name = "Day " & Sheet1.Name
End Sub