+ Reply to Thread
Results 1 to 22 of 22

vba to extract formula with values

  1. #1
    Forum Contributor
    Join Date
    09-21-2015
    Location
    Alexandria
    MS-Off Ver
    2013
    Posts
    106

    vba to extract formula with values

    Hallo! I have a workbook with multiple worksheets.

    Is there a vba so i can extract the formula with values from a cell.

    eg. lets say there are 2 worksheets: 1 and 2.

    A1 in worksheet 1 has a formula that gives as a result 1 and

    A1 in worksheet 2 has a formula that gives as a result 2


    a formula in a cell in worksheet 2 is: = 1!A1 + A1, so i want it to display: 1+2

    Is there a vba that works like that?

  2. #2
    Forum Contributor
    Join Date
    11-12-2012
    Location
    Jeddah, Saudi Arabia
    MS-Off Ver
    2010, 2013, 2016, Office 365
    Posts
    521

    Re: vba to extract formula with values

    try using formula

    Please Login or Register  to view this content.

  3. #3
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,298

    Re: vba to extract formula with values

    This will work - maybe - as long as your sheet names don't have spaces - written to process just the activecell:

    Please Login or Register  to view this content.
    Bernie Deitrick
    Excel MVP 2000-2010

  4. #4
    Forum Contributor
    Join Date
    09-21-2015
    Location
    Alexandria
    MS-Off Ver
    2013
    Posts
    106

    Re: vba to extract formula with values

    Quote Originally Posted by Barieq View Post
    try using formula

    Please Login or Register  to view this content.
    Thanks, it works, but too much manual work for many cells, with complex formulas.

  5. #5
    Forum Contributor
    Join Date
    09-21-2015
    Location
    Alexandria
    MS-Off Ver
    2013
    Posts
    106

    Re: vba to extract formula with values

    Quote Originally Posted by Bernie Deitrick View Post
    This will work - maybe - as long as your sheet names don't have spaces - written to process just the activecell:

    Please Login or Register  to view this content.
    Thank you, i'll try it, but what is the formula that i enter in order to use this vba module?

  6. #6
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,298

    Re: vba to extract formula with values

    If you want it as a function, then try this code, used like

    =ReplaceReferences(A2)

    where A2 has the formula you want evaluated.

    Please Login or Register  to view this content.

  7. #7
    Forum Contributor
    Join Date
    09-21-2015
    Location
    Alexandria
    MS-Off Ver
    2013
    Posts
    106

    Re: vba to extract formula with values

    Thanks, i get this message

    r.png

  8. #8
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,298

    Re: vba to extract formula with values

    Sorry - I should have told you to remove the old subroutine code, or comment it out.

  9. #9
    Registered User
    Join Date
    11-29-2022
    Location
    Lahore, Pakistan
    MS-Off Ver
    MS Office 2007
    Posts
    70

    Re: vba to extract formula with values

    Quote Originally Posted by Bernie Deitrick View Post
    Sorry - I should have told you to remove the old subroutine code, or comment it out.
    Sir, If you have a free time, then please look into my thread too available in your visitor's messages. Thanks.

  10. #10
    Forum Contributor
    Join Date
    09-21-2015
    Location
    Alexandria
    MS-Off Ver
    2013
    Posts
    106

    Re: vba to extract formula with values

    I didn't save the routine in your third message
    https://www.excelforum.com/excel-pro...ml#post5881955

    This message is there unfortunately. I am be doing something wrong.

    I noticed also that macros are blank. Shouldn't there be a macro name replacereferences?

    rr.png
    Last edited by freeriding; 10-17-2023 at 07:05 PM.

  11. #11
    Registered User
    Join Date
    11-29-2022
    Location
    Lahore, Pakistan
    MS-Off Ver
    MS Office 2007
    Posts
    70

    Re: vba to extract formula with values

    Quote Originally Posted by freeriding View Post
    I didn't save the routine in your third message
    https://www.excelforum.com/excel-pro...ml#post5881955

    This message is there unfortunately. I am be doing something wrong.
    Just Change the Last line
    End Sub
    to
    End Function

  12. #12
    Forum Contributor
    Join Date
    09-21-2015
    Location
    Alexandria
    MS-Off Ver
    2013
    Posts
    106

    Re: vba to extract formula with values

    Thank you, it works fine!!!
    Just doesn't work for worksheets that contain space in their name.

  13. #13
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,298

    Re: vba to extract formula with values

    D'oh! Thank you for catching that!

  14. #14
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,298

    Re: vba to extract formula with values

    Yes - it can be changed to work with sheets named with spaces - It just requires a different delimiter and that creates other possible complications... so I chose no spaces in the sheet names.

  15. #15
    Forum Contributor
    Join Date
    09-21-2015
    Location
    Alexandria
    MS-Off Ver
    2013
    Posts
    106

    Re: vba to extract formula with values

    I noticed that you remarked it, i just confirm it.
    Is there a solution so that space containing worksheets don't create a problem?

  16. #16
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,474

    Re: vba to extract formula with values

    Try this variation on Bernie's function. If a worksheetname has spaces, you can specify a delimiter, for example "|"

    Please Login or Register  to view this content.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  17. #17
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,474

    Re: vba to extract formula with values

    I don't think you need the single quote:
    Please Login or Register  to view this content.

  18. #18
    Forum Contributor
    Join Date
    09-21-2015
    Location
    Alexandria
    MS-Off Ver
    2013
    Posts
    106

    Re: vba to extract formula with values

    Thank you!

  19. #19
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,474

    Re: vba to extract formula with values

    You're welcome.



    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

    Also, you may not be aware that you can thank those who have helped you by clicking the small star icon located in the lower left corner of the post in which the help was given. By doing so you can add to the reputation(s) of those who helped.

  20. #20
    Forum Contributor
    Join Date
    09-21-2015
    Location
    Alexandria
    MS-Off Ver
    2013
    Posts
    106

    Re: vba to extract formula with values

    Hallo, when the formula is like =(A-B)*C, why does it show #value?

  21. #21
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,298

    Re: vba to extract formula with values

    Because this line:

    strR = "+-*&^=><,/"

    does not include ( and ).

    I did that so that something like

    =SUM(A:A)

    would not blow up the function by trying to include all of A in the result, but would show the SUM() result.

    You can change that line to this to fix your issue:

    strR = "+-*&^=><,/()"

  22. #22
    Forum Contributor
    Join Date
    09-21-2015
    Location
    Alexandria
    MS-Off Ver
    2013
    Posts
    106

    Re: vba to extract formula with values

    Thank you!!!

+ 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. Formula to extract unique values/distinct values in rows in excel
    By bjnockle in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 05-07-2020, 05:35 PM
  2. Non Array Formula to Extract Values
    By bjnockle in forum Excel Formulas & Functions
    Replies: 12
    Last Post: 03-31-2018, 04:50 AM
  3. Replies: 11
    Last Post: 10-27-2016, 07:33 PM
  4. Extract Values using formula
    By bjnockle in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 03-21-2016, 09:32 AM
  5. [SOLVED] Extract values (row values and column values) with formula
    By bjnockle in forum Excel Formulas & Functions
    Replies: 14
    Last Post: 08-17-2014, 10:13 AM
  6. [SOLVED] Formula to extract values
    By Buster^ in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 06-21-2014, 05:09 AM
  7. Formula to Extract Values within a Range
    By prkhan56 in forum Excel General
    Replies: 3
    Last Post: 07-21-2005, 02: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