Automatically change a file name using a variable

Solved
robbybasch Posted messages 101 Status Member -  
robbybasch Posted messages 101 Status Member -
Hello
I am working on Excel 2010 and I am creating an accounting workbook for an association.
1- My problem:
In the accounting balance sheet, I am calculating a difference between the current year and the previous year. I will therefore fetch data from last year's workbook, which is named: '[2013_accounting.xlsm]balance'E10. In this sheet, I have this formula 30 times. When the new year arrives, I change the fiscal year in my "data" sheet in a cell that I named fiscal_year.
2- Question:
Is it possible to place "fiscal_year" as a variable to automatically replace the previous year's formula in the filename (for example [fiscal_year_accounting.xlsm]balance'E10) so that I do not have to copy and change the year in all the formulas for the differences in the balance sheet, and also in the income statement sheet where I have the same formula. I think that through a function, this is not possible (at least I haven't found one), would it be possible through a VBA macro? I don’t know the language, if someone could give me a bit of a boost on that side, that would be great..
Thank you in advance for your suggestions
Robby

6 answers

  1. via55 Posted messages 14393 Registration date   Status Member Last intervention   2 759
     
    Good evening

    It is possible with the INDIRECT function as long as the source workbook is open at the same time as the target workbook:

    - Put the year variable in a cell, for example in B1
    - Replace the formula with:
    =INDIRECT("'[" & B1 & "_accounting.xlsm]balance'!E10")

    Of course, B1 can be named and that name will then be used in the formula (especially useful if you want to place the B1 data in another sheet)

    Best regards

    "Imagination is more important than knowledge." A. Einstein
    0