Hi all,
I use a Template to create 12 monthly workbooks.
Each workbook has 9-10 sheets with it.
The template runs macros to format each monthly file, namely:-
I have a macro that is called ConsolidateExpenses that is run at the end of the month once all data is entered in the weekly sheets. It extracts required data from the weekly sheets. In the macro there is a statement which reads
.
My problem is that this is the last macro to run in the workbook and prior to getting to this place, sheets called Sheet1, Sheet2, Sheet3, Sheet4 and Sheet5 have been renamed to something like 03-Jan-21, 10-Jan-21, 17-Jan-21, 24-Jan-21 and 31-Jan-21.
Is there a way that the array formula in ConsolidateExpenses can automatically change to
Obviously, for February 21 the array should read
The renamed sheet names exist in Sheet called Formula in Cells O3 to O7 and the number of weeks in the month exists in H2.
There is an added complication, which I have. Certain months with have 4 weeks and certain months will have 5 weeks, therefore cell O7 within Formula will have #REF! when there are only 4 weeks as the Sheet5 will have been deleted.
The only way I was thinking of achieving my goal was to do the following in macro called ConsolidateExpenses
Can anyone suggest a solution?
I use a Template to create 12 monthly workbooks.
Each workbook has 9-10 sheets with it.
The template runs macros to format each monthly file, namely:-
- inserts dates in certain rows,
- check how many weeks are in the month,
- if there are only 4 weeks, delete sheet called Sheet5,
- Finally renames Sheets called Sheet1….Sheet5 with a date in the format dd-mmm-yy (i.e. 03-Jan-21, 10-Jan-21, 17-Jan-21, 24-Jan-21 and 31-Jan-21).
I have a macro that is called ConsolidateExpenses that is run at the end of the month once all data is entered in the weekly sheets. It extracts required data from the weekly sheets. In the macro there is a statement which reads
VBA Code:
sht = Array("Sheet1", "Sheet2", "Sheet3", "Sheet4", "Sheet5")
My problem is that this is the last macro to run in the workbook and prior to getting to this place, sheets called Sheet1, Sheet2, Sheet3, Sheet4 and Sheet5 have been renamed to something like 03-Jan-21, 10-Jan-21, 17-Jan-21, 24-Jan-21 and 31-Jan-21.
Is there a way that the array formula in ConsolidateExpenses can automatically change to
VBA Code:
sht = Array("03-Jan-21”, “10-Jan-21”, “17-Jan-21”, “24-Jan-212”, “31-Jan-21”)
Obviously, for February 21 the array should read
VBA Code:
sht = Array("07-Feb-21”, “14-Feb-21”, “21-Feb-21”, “28-Feb-21”)
The renamed sheet names exist in Sheet called Formula in Cells O3 to O7 and the number of weeks in the month exists in H2.
There is an added complication, which I have. Certain months with have 4 weeks and certain months will have 5 weeks, therefore cell O7 within Formula will have #REF! when there are only 4 weeks as the Sheet5 will have been deleted.
The only way I was thinking of achieving my goal was to do the following in macro called ConsolidateExpenses
- Getting and storing the renamed sheets names from sheet formula cells O2 to O7;
- Getting and storing the no of weeks from sheet Formula H2;
- Renaming the sheets to Sheet1, Sheet2… from their existing names;
- Setting the array as sht = Array("Sheet1", "Sheet2", "Sheet3", "Sheet4"), if no of weeks is 4 or setting it to sht = Array("Sheet1", "Sheet2", "Sheet3", "Sheet4", "Sheet5") if the number of weeks are 5;
- Consolidate the data;
- Renaming the sheets back to what they were.
Can anyone suggest a solution?