TheWennerWoman
Active Member
- Joined
- Aug 1, 2019
- Messages
- 303
- Office Version
- 365
- Platform
- Windows
I have a master sheet with lots of data and have a routine that splits it into a number of sheets, depending on the number of records chosen by the user. So if there are 100,000 records in the master sheet and the user choses 20,000, the routine will create five new sheets.
I am trying to future-proof this so have the following
How can I amend the above to only add the formula if the sheet exists? In the above, journal_6 onwards wouldn't exist in this example.
I am trying to future-proof this so have the following
VBA Code:
Sheets("Control").Select
Range("E81").FormulaR1C1 = "=IFERROR(journal_1!R[-76]C[4],"""")"
Range("E82").FormulaR1C1 = "=IFERROR(journal_2!R[-77]C[4],"""")"
Range("E83").FormulaR1C1 = "=IFERROR(journal_3!R[-78]C[4],"""")"
Range("E84").FormulaR1C1 = "=IFERROR(journal_4!R[-79]C[4],"""")"
Range("E85").FormulaR1C1 = "=IFERROR(journal_5!R[-80]C[4],"""")"
Range("E86").FormulaR1C1 = "=IFERROR(journal_6!R[-81]C[4],"""")"
Range("E87").FormulaR1C1 = "=IFERROR(journal_7!R[-82]C[4],"""")"
Range("E88").FormulaR1C1 = "=IFERROR(journal_8!R[-83]C[4],"""")"
Range("E89").FormulaR1C1 = "=IFERROR(journal_9!R[-84]C[4],"""")"
Range("E90").FormulaR1C1 = "=IFERROR(journal_10!R[-85]C[4],"""")"
Range("E91").FormulaR1C1 = "=IFERROR(journal_11!R[-86]C[4],"""")"
Range("E92").FormulaR1C1 = "=IFERROR(journal_12!R[-87]C[4],"""")"
How can I amend the above to only add the formula if the sheet exists? In the above, journal_6 onwards wouldn't exist in this example.