Consulting

Results 1 to 4 of 4

Thread: Changeing links source with VBA

  1. #1
    VBAX Regular
    Joined
    Oct 2004
    Posts
    65
    Location

    Changeing links source with VBA

    I have a sheet with formulas that pull data off an other excel WB. The issue is that I don't create these workbooks and they are always coming in with a different name. I was wondering if any VBA code that I could press a button and browse to the source of the links and update them instead of every day hitting edit links change source etc

    Any help is appreciated
    We are living in a world today
    where lemonade is made from
    artificial flavoring and furniture polish
    is made from real lemons...
    Alfred E Newman

  2. #2
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    Take a look at the Indirect function. Instead of using Sheet1 for example use
     =INDIRECT(A1 & "!A1")
    .

    A1 will hold the sheet name. Then just build your formula within the Indirect function.

    For example if in A1 you type MySheet then the formula would evaluate to =MySheet!A1 and would then get the value from A1 in MySheet.

    This way all you have to do is change the value in A1 whenever you want to refer to another sheet.

  3. #3
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    To expand on Jake's comments, if you're dealing with another workbook (which must be open), the text in cell A1 would be in the form [Data.xls]sheet1
    If you need your formula to be dynamic, you might use something like
    =INDIRECT($A$1& "!A" & ROW()-11)
    , depending upon your offset.
    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
    VBAX Regular
    Joined
    Oct 2004
    Posts
    65
    Location
    Thanks to all I'll check this out
    We are living in a world today
    where lemonade is made from
    artificial flavoring and furniture polish
    is made from real lemons...
    Alfred E Newman

Posting Permissions

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