+ Reply to Thread
Results 1 to 9 of 9

VBA to replace value in formula in range

  1. #1
    Forum Contributor
    Join Date
    03-08-2011
    Location
    London
    MS-Off Ver
    Work Office 365 Home 2019
    Posts
    428

    VBA to replace value in formula in range

    Hi Team,

    I'm looking for a macro tthat would find a specific value (Cell E2 in sample) in a formula in range F4:F50 and replace all instances of the value of cell E2 with the value in cell E1 without compromising the formula.

    In short the formula in F4:
    Please Login or Register  to view this content.
    would become:
    Please Login or Register  to view this content.
    and so on down to F50

    Many thanks

    MagicMan

    P.S: The values in cells E1 and E2 are driven by D1 which is in turn calculated from C1 (from A4)
    A4 = Text with date at end
    C1 = Date extrapolated from A4
    D1 = Date from C1 as text
    E1 = D1 - 1
    E2 = D1 - 2
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    10-09-2014
    Location
    Newcastle, England
    MS-Off Ver
    2003 & 2013
    Posts
    1,986

    Re: VBA to replace value in formula in range

    I'm probably missing something fundamental here but why not just replace the value with D1 - 1 ?
    If someone has helped you then please add to their Reputation

  3. #3
    Forum Contributor
    Join Date
    03-08-2011
    Location
    London
    MS-Off Ver
    Work Office 365 Home 2019
    Posts
    428

    Re: VBA to replace value in formula in range

    Hi PJ

    I'm not sure I follow your thoughts.

    The value I want replacing refers to other sheets that will be created. I'm not sure if you mean replacing the sheet reference to D1-1. That would remove the sheet reference which would kill the formula.

    MM

  4. #4
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,258

    Re: VBA to replace value in formula in range

    The basic code would be something like:

    Please Login or Register  to view this content.
    Remember what the dormouse said
    Feed your head

  5. #5
    Forum Contributor
    Join Date
    03-08-2011
    Location
    London
    MS-Off Ver
    Work Office 365 Home 2019
    Posts
    428

    Re: VBA to replace value in formula in range

    Hi Team,

    Doing a bit of research and it's a bit ugly, but I've got this far and it works for cell F3, I just need it to loop until the end of the formulas in this column.

    Please Login or Register  to view this content.
    I'm quite happy for it to loop.

    Any ideas?

    MM

  6. #6
    Forum Contributor
    Join Date
    03-08-2011
    Location
    London
    MS-Off Ver
    Work Office 365 Home 2019
    Posts
    428

    Re: VBA to replace value in formula in range

    It's not pretty, and always open to improvements, but finally come up with this ...
    Please Login or Register  to view this content.

  7. #7
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,258

    Re: VBA to replace value in formula in range

    Was there something wrong with post 4?

  8. #8
    Forum Contributor
    Join Date
    03-08-2011
    Location
    London
    MS-Off Ver
    Work Office 365 Home 2019
    Posts
    428
    Quote Originally Posted by rorya View Post
    Was there something wrong with post 4?
    Hi Rorya,

    Not as far as im aware mate. Didnt see it until too late.

    I'll certainly try it and, if its faster than what I've done,... Happy days! I'll use it 😀

  9. #9
    Forum Contributor
    Join Date
    03-08-2011
    Location
    London
    MS-Off Ver
    Work Office 365 Home 2019
    Posts
    428

    Re: VBA to replace value in formula in range

    Hi Rorya,

    I've now had a chance to test it and WOW!!! So much simpler and so quick (it was that quick (when compared to the rubbish I had put together), I had to run it twice just to confirm it had run )

    Rep added and many thanks,

    MM

+ 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. Excel formula to replace range reference with dynamic range
    By mp3909 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 05-12-2021, 03:32 PM
  2. In a formula replace the value of a cell by a range of values
    By ALOHA in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 10-12-2017, 06:08 PM
  3. replace part of string in the range.formula
    By dluhut in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-23-2017, 01:31 PM
  4. [SOLVED] Replace formula in range of cells (with/without if then statement)
    By bjprent in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-29-2016, 08:56 AM
  5. [SOLVED] How can I replace the range with a Name in a INDIRECT Formula?
    By trizzo in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 02-02-2013, 04:31 PM
  6. Replace range of cells with a formula
    By dcgrove in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-22-2010, 07:48 PM
  7. [SOLVED] Need code to replace part of a range within a formula with a defined name
    By Jeff in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-02-2006, 06:10 PM

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