+ Reply to Thread
Results 1 to 10 of 10

VBA to change part of formula

  1. #1
    Forum Contributor ABSTRAKTUS's Avatar
    Join Date
    04-18-2010
    Location
    England
    MS-Off Ver
    Win10 Excel 2016
    Posts
    609

    VBA to change part of formula

    Hi all,

    This one will not be easy I believe. Assume you have a workbook "A" that is linked to workbook "B". The problem is that workbook B file name and sheet name is changing every day, therefore links in workbook A will be broken. Is there a way to write a macro in workbook A that would change references within formulas?

    Thanks
    Last edited by ABSTRAKTUS; 02-03-2012 at 10:40 AM.

  2. #2
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: VBA to change part of formula

    Something like this, perhaps?

    Please Login or Register  to view this content.
    That will change all references on the active sheet, but you'll have to add some code to ask for, or work out, the old and new file names.

  3. #3
    Forum Contributor ABSTRAKTUS's Avatar
    Join Date
    04-18-2010
    Location
    England
    MS-Off Ver
    Win10 Excel 2016
    Posts
    609

    Re: VBA to change part of formula

    Idealy I would like user to be able to hit a button that would call windows browser. User then chooses what workbook to pull information from and depending on users choice formulas in the workbook would relink to chosen workbook. Is this doable? Honestly, I need to remove human factor as much as possible (no rewriting formulas, no typing etc. as not all of our users have more than one brain cell).

  4. #4
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: VBA to change part of formula

    Something like this, then ...

    Please Login or Register  to view this content.
    It opens the file dialogue box to let the user select a new file name.

    The value sREFERENCE_CELL points to a cell which contains a formula which has the old file name in, and the old file name is picked up from there.

    Does that work for you?

  5. #5
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: VBA to change part of formula

    Have you tried the Edit Links dialog?
    Good luck.

  6. #6
    Forum Contributor ABSTRAKTUS's Avatar
    Join Date
    04-18-2010
    Location
    England
    MS-Off Ver
    Win10 Excel 2016
    Posts
    609

    Re: VBA to change part of formula

    Spot on Andrew-R!!!, exactly what I'm looking for! Good job! Thanks!

  7. #7
    Forum Contributor ABSTRAKTUS's Avatar
    Join Date
    04-18-2010
    Location
    England
    MS-Off Ver
    Win10 Excel 2016
    Posts
    609

    Re: VBA to change part of formula

    The only thing, it is not one cell (A1), it is a whole range. Where and what to change within the code?

  8. #8
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: VBA to change part of formula

    It should change all cells, it just needs one cell with the old file name in that it can extract it from.

  9. #9
    Forum Contributor ABSTRAKTUS's Avatar
    Join Date
    04-18-2010
    Location
    England
    MS-Off Ver
    Win10 Excel 2016
    Posts
    609

    Re: VBA to change part of formula

    Yes< got it now. Thanks mate!

  10. #10
    Forum Contributor ABSTRAKTUS's Avatar
    Join Date
    04-18-2010
    Location
    England
    MS-Off Ver
    Win10 Excel 2016
    Posts
    609

    Re: VBA to change part of formula

    Just realized that code doesn't change the tab name. When I selected different workbook, formulas have ruturned REF errors. Any idea?

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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