Consulting

Results 1 to 10 of 10

Thread: File with a lot of links

  1. #1

    File with a lot of links

    Hi all,

    In the attached Excel file (Please open):

    The red colored part is changeable in formula part. Instead of changing the link (file name) manually every line, Is there a formula, code or macro can do this for me. Especially there are 3224 rows of formula for same Please help.
    Pls see attached file.
    Attached Files Attached Files

  2. #2
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    How will you know which number to use for which line?, there's no pattern to the numbering, when would you want to trigger the change?, do you have all these nubers stored somewhere?
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  3. #3
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Check out the Indirect function.
    Something like
    =INDIRECT("'C:\Qtel\04895087\2010-April\QtelRecovery\Files\["& RIGHT(A6,22)&"]QtelRecovery" &"'!$C$7")
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  4. #4
    Thanks for your help,

    I tried the above formula but it didn't work.

  5. #5
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    While you can set the full path, it matters little. Indirect() expects the file to be open or you get #ref. There is a way to use VBA to get data from a closed file.

    String to Build where the fullpathname is in A6:
    'C:\Bill\04895087\2010-April\BillRecovery\Files\[Mob-04-2010-100642.xls]Recovery'!$C$7
    Formula:
    =INDIRECT("'" & LEFT(A6,47) & "[" & RIGHT(A6, 22) & "]Recovery'!$C$7")
    Or:
    =INDIRECT("'" & "[" & RIGHT(A6, 22) & "]Recovery'!$C$7")
    For Indirect() syntax see:
    http://www.contextures.com/xlFunctions05.html

  6. #6
    Thanks a lot Kenneth, but still not working showing "#Ref!".

    Again I'm very thankful for your help.

  7. #7
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    If you built the string properly AND the file is open, AND the sheetname exists, then you won't get that error.

    Type the path in manually if need be to check.

  8. #8
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Try the formula without the Indirect. You should see the desired address. Check it and correct for any errors
    ="'" & LEFT(A6,47) & "[" & RIGHT(A6, 22) & "]Recovery'!$C$7"
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  9. #9
    Although the file was opened but both formulas didn't work.

    Thankful for your help.

  10. #10
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    Since we can't look over your shoulder, you will have to troubleshoot the problem yourself. mdmackillop showed you a trick to view your string for the Indirect() function. The link that I gave showed the syntax.

    In my A6:
    C:\Bill\04895087\2010-April\BillRecovery\Files\Mob-04-2010-100642.xls
    I saved a file with name t:\test\Mob-04-2010-100642.xls and opened it. I did not have a sheet named Recovery so I used Sheet1. The path is not the same but Excel only allows one file with the same name to be open at once.

    To check my formula: ="'" & "[" & RIGHT(A6, 22) & "]Sheet1'!$C$7"
    Which resolves to: '[Mob-04-2010-100642.xls]Sheet1'!$C$7

    The Indirect formula is then: =Indirect("'" & "[" & RIGHT(A6, 22) & "]Sheet1'!$C$7")

    If I close Mob-04-2010-100642.xls, nothing is changed with the Indirect() value until a recalculation happens which will then show #REF.

Posting Permissions

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