We’d like to remind Forumites to please avoid political debate on the Forum.

This is to keep it a safe and useful space for MoneySaving discussions. Threads that are – or become – political in nature may be removed in line with the Forum’s rules. Thank you for your understanding.

Excel - link to file named in a cell

Not sure I'm explaining this correctly, but here goes.. (using Excel 2007)


I have series of spreadsheets I use for budgeting, all in the same folder, and named 2017, 2018, 2019, ....etc

It's set so that when I update the year in cell A1, all necessary cells update accordingly, but only for internal cells. I haven't found a method of getting it to automatically update links to external workbooks at the same time.


For example, I have a cell containing


='C:\Documents\[2018.xlsx]transfer'!N3

but instead of manually changing 2018 to 2019 when I create a new sheet, I'd like to have a formula that does it for me, so assuming cell A1 contains '2018', the link


='C:\Documents\[=A1.xlsx]transfer'!N3

would display the same as before, but when I amend cell A1 to 2019, the link/formula would display the contents of the cell in workbook 2019.xlsx instead.


I found a suggestion for using the INDIRECT function, but then it said the external spreadsheet has to be open for it to work, which I don't want to do.


Just for reference, my current system is to use find/replace to update all the links, until I remember that I can simply go to 'Edit Links', Change Source' and change them all in about 2 seconds.:wall:
Due to the memory getting worse I decided I'd like to 'automate' this simple task.
Is there a formula to do what I want, or should I just add myself a reminder somewhere of the simple way to do it?

Comments

  • KingL
    KingL Posts: 1,713 Forumite
    I'm sure that there must be better ways, but you could find an empty cell and reconstruct the text of your formula as a text string:
    ="'c:\documents\["&A1&".xlsx]transfer'!N4"

    You would then have to copy-paste that as values and manually stick an equals sign on the front.

    or should I just add myself a reminder somewhere of the simple way to do it?
    sounds like a plan :)
  • Do it all in a macro that you can run from a button or that automatically runs upon opening your spreadsheet?


    Idea being (my assumption here) is that you want to do the year change when a new year starts?


    So, macro runs, tests if the cell contains the current year, if so exits.
    If not continues to run/call another procedure to do the modification, then exits.


    The macro vba code can be produced by starting the 'record a macro' process and then making all the changes you do currently and then stopping the recording.


    Hence you can have a macro you call and it does all the work for you (which can include opening your spreadsheet just in the background then closing it) or runs fully when you when you open the workbook you wish to modify. It can therefore create the 'next year's ' sheet too.....and lots more.


    The recorded macro sometimes needs a bit of tweaking but basically self documents thethe script.
  • VoucherMan
    VoucherMan Posts: 2,807
    Part of the Furniture 1,000 Posts Name Dropper
    Forumite
    Do it all in a macro that you can run from a button or that automatically runs upon opening your spreadsheet?


    Idea being (my assumption here) is that you want to do the year change when a new year starts?


    So, macro runs, tests if the cell contains the current year, if so exits.
    If not continues to run/call another procedure to do the modification, then exits.


    I like the idea, but I think it will be beyond my imagination, at least for now. If I record a macro like that I manually enter the old & new years, so they would be different for every file. Similarly if I use the 'Edit Links' option I'm also replacing the old with the new. I'm guessing for the code required here to be universal, it would have to be written manually.

    Cells.Replace What:="2023", Replacement:="2024", LookAt:=xlPart, _
            SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
            ReplaceFormat:=False
        ActiveWorkbook.ChangeLink Name:="C:\Documents\2023.xlsx", _
             NewName:="C:\Documents\2024.xlsx", Type:=xlExcelLinks
    
    The other drawback is that I often prepare the workbooks in batches. When I find I'm about to use my last workbook I'll create another 4 or 5 for the subsequent years. This makes the bad memory problem worse as I only create the new copies once every 4 or 5 years, giving me plenty of time to forget how to update them. I have considered just creating enough future spreadsheets to last until the end of the century, or at least as long as I may have a use for them, but you can almost guarantee that as soon as I do that, I'll make some change to the layout that I want copied across to future copies.


    In the absence of a built in function I am favouring the 'reminder' option. Not as interesting to create, but far simpler.
  • Rather than keep separate workbooks 2017, 2018 etc, why not make these separate worksheets in a single workbook? The INDIRECT option would then work without opening another workbook.
  • VoucherMan
    VoucherMan Posts: 2,807
    Part of the Furniture 1,000 Posts Name Dropper
    Forumite
    Rather than keep separate workbooks 2017, 2018 etc, why not make these separate worksheets in a single workbook?


    Old habits die hard. Plus I've been using the same basic spreadsheet for over 10 years now and it's easier this way.


    Each workbook is already spread out over several sheets, so trying to combine multiple workbooks would, I think be more trouble than it's worth. The spreadsheets wouldn't win any awards, unless they hand them out for untidy mess, but I've been slowly adding, removing and updating bits over the years as needs change, and they way they are now is ideal for me to keep track of finances past, present & future estimates.
  • VoucherMan wrote: »
    Each workbook is already spread out over several sheets, so trying to combine multiple workbooks would, I think be more trouble than it's worth.
    You could rename sheets as 2017_1, 2017_2, 2018_1 etc - formulae should automatically adjust. Bit of an effort but one-off exercise may be worth it in long run. Max number of worksheets is 255 but may be limited by available memory.
    Alternatively tested in Excel 2016 and when opening workbook with external links, get prompt to update. Selecting update seems to do this without opening linked workbook.
This discussion has been closed.
★ ★ ★ Meet your Ambassadors

Categories

  • All Categories
  • 356K Banking & Borrowing
  • 255K Reduce Debt & Boost Income
  • 456.3K Spending & Discounts
  • 248.5K Work, Benefits & Business
  • 606.4K Mortgages, Homes & Bills
  • 179.1K Life & Family
  • 264.1K Travel & Transport
  • 1.6M Hobbies & Leisure
  • 16.2K Discuss & Feedback
  • 37.7K Read-Only Boards
Quick Search

Is this how you want to be seen?

We see you are using a default avatar. It takes only a few seconds to pick a picture.