+ Reply to Thread
Results 1 to 13 of 13

Variable link in a reference

  1. #1
    Registered User
    Join Date
    06-16-2016
    Location
    Belgium
    MS-Off Ver
    2010
    Posts
    7

    Cool Variable link in a reference

    Hello everyone!

    I hope someone here can help me... I want to make an overview file which gathers data from different excel files. Just one problem: due to historic reasons we create a new file each day, so if I want to create an overview of one year i have to enter 365 references, which is a bit much.

    Cell A1 contains a formula like this:
    Please Login or Register  to view this content.
    linking to the file where i want to get one number.

    Cell A2 will be the same reference but with the date changed (it's always in the same location and same format):
    Please Login or Register  to view this content.
    and so on... Is there a way I can make inserting the reference automatically? So that I don't have to enter it until 2017 and beyond?

    I tried something with concatenate but then it's just text and no longer a reference...
    Last edited by Vincent_df; 06-16-2016 at 08:50 AM.

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2404
    Posts
    24,765

    Re: Variable link in a reference

    I think you're going to need to do this with macros. You can use INDIRECT but that would require the 365 files to be open for the formulas to update and I am guessing that is not practical for you.

    My approach would be to write a macro that writes the formulas into the corresponding cells for you. It could update the file to add formulas up to the current date. You do not want to run this code unless the referenced file exist! If a file does not exist then Excel will prompt you to locate it when you try to populate the formula.

    Please Login or Register  to view this content.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Variable link in a reference

    Hi,

    Here's another approach using the Edit Links functionaility

    Put your A1 formula in another cell and name it "LinkFormula"

    Now in C1:C365 list all your file names

    Then run the following macro

    Please Login or Register  to view this content.
    Obviously edit the path "C:\Users\Richard\Desktop" to your path
    The G6 value will be listed in A1:A365
    Last edited by Richard Buttrey; 06-16-2016 at 10:41 AM.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  4. #4
    Registered User
    Join Date
    06-16-2016
    Location
    Belgium
    MS-Off Ver
    2010
    Posts
    7

    Re: Variable link in a reference

    Hey both of you thanks for the fast reply.



    I've only tried Jeff's way for now and it works (although I indeed have to cancel the prompt on sundays (no file on sundays :D) but that is not an issue. )

    This helps me insert all the data up until today but tomorrow I still have to manually add the new data (and this every new day), or run the whole macro again (it took quite some time).
    First part of the solution would be to create an 'update' macro just for the previous week.
    Please Login or Register  to view this content.
    But then he would overwrite existing data in cell A1. And even if I'd change the macro so he adds it at the bottom of the list he would create duplicate values for all the data already in it. and still prompt me for sundays

  5. #5
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2404
    Posts
    24,765

    Re: Variable link in a reference

    Quote Originally Posted by Vincent_df View Post
    [...]I indeed have to cancel the prompt on sundays (no file on sundays :D) but that is not an issue. )
    You did mention 365 days. The code can be modified to exclude Sundays.
    This helps me insert all the data up until today but tomorrow I still have to manually add the new data (and this every new day), or run the whole macro again (it took quite some time).
    First part of the solution would be to create an 'update' macro just for the previous week.
    Please Login or Register  to view this content.
    But then he would overwrite existing data in cell A1. And even if I'd change the macro so he adds it at the bottom of the list he would create duplicate values for all the data already in it. and still prompt me for sundays
    It can be modified to just add days at the end of the list. I am surprised that it took quite some time because for me it was maybe 1 second.

    I don't have time to update now but will get back to you.

  6. #6
    Registered User
    Join Date
    06-16-2016
    Location
    Belgium
    MS-Off Ver
    2010
    Posts
    7

    Re: Variable link in a reference

    Company servers; not that fast.

    I tried to exclude sundays but I just created a lot of syntax errors I'm afraid. As to the part about adding it to the end, I have no clue how to start there.
    In any case, thanks alot for the first step already!

    Vincent

  7. #7
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2404
    Posts
    24,765

    Re: Variable link in a reference

    Here is an update that will skip Sundays. It also starts in the next available row to fill up to today's date, rather than starting from the beginning.

    However, I'll say again that this takes under a second for me to run for a whole year, so I don't know why you are experiencing "it took quite some time". What OS and hardware are you using?

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    06-16-2016
    Location
    Belgium
    MS-Off Ver
    2010
    Posts
    7

    Re: Variable link in a reference

    Wow, thanks. I can understand the code although I'd never be able to make it myself without VBA training. (or any language training for that matter).

    I'm running a company laptop, 64bit Win7, 8GB ram, Intel i5 CPU (2.7Ghz) which is more than fine but the C:/ drive is on the company network, which is tremendously slow . (my local drive is L:/)

    I'll try the code now. Already a great thanks for the help!



    First run it works great! second run, when there already is data, it gives a Run-time error '13' Type mismatch. Debugger put this in yellow:
    Please Login or Register  to view this content.
    OR the next time it puts this in yellow:

    Please Login or Register  to view this content.
    Last edited by Vincent_df; 06-20-2016 at 02:30 AM.

  9. #9
    Registered User
    Join Date
    06-16-2016
    Location
    Belgium
    MS-Off Ver
    2010
    Posts
    7

    Re: Variable link in a reference

    I have tried to change a few things but can't seem to find the reason for the type mismatch. Anyone?

  10. #10
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2404
    Posts
    24,765

    Re: Variable link in a reference

    I have been very busy the last few days but I will take a look at this tomorrow if nobody else drops in. I tested it before I gave it to you and I did not have these problems, but I'll try a few different things to see if I can get the same error.

  11. #11
    Registered User
    Join Date
    06-16-2016
    Location
    Belgium
    MS-Off Ver
    2010
    Posts
    7

    Re: Variable link in a reference

    Thanks it happens when i load data in an empty sheet and then delete the last few entries to simulate only running the macro every few days. Then when I rerun i get the fault.

    I've changed the syntax of the arguments into alternative ways of saying the same but i just create more errors

  12. #12
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2404
    Posts
    24,765

    Re: Variable link in a reference

    I do see an error in the code that will cause your problem. I also see another error. Changes highlighted.

    Here is a revised version of the code which I tested in a setup like yours. Because C is a network drive, the I/O latency is going to make this slow as Excel verifies the external references when they are created. Suppressing screen updates might help, but I don't have a networked drive I can test this on to find out.
    Please Login or Register  to view this content.

  13. #13
    Registered User
    Join Date
    06-16-2016
    Location
    Belgium
    MS-Off Ver
    2010
    Posts
    7

    Re: Variable link in a reference

    the missing ' I had already corrected. Your other changes have indeed resolved the issue !!! Thanks so much


    V

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 2
    Last Post: 03-02-2016, 07:05 AM
  2. Using a variable in a link
    By mowens74 in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 03-26-2014, 09:06 AM
  3. Variable Cell with Variable Reference
    By AndrewR1114 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 12-12-2012, 03:12 AM
  4. Variable File Reference and Variable Table Array in VBA VLOOKUP
    By Gingeiko in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-28-2011, 11:08 PM
  5. How do I link to a workbook whose name is variable?
    By Carl Borthwick in forum Excel General
    Replies: 1
    Last Post: 01-13-2006, 06:10 AM
  6. Create an external reference link with embedded variable
    By Greentree in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 10-09-2005, 03:05 PM
  7. variable in a link where the variable is the name of the sheet
    By darrelly in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 10-07-2005, 04:05 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1