+ Reply to Thread
Results 1 to 15 of 15

How do I get the value, rather than the formula, in a cell with VBA

  1. #1
    Forum Contributor
    Join Date
    08-19-2009
    Location
    Netherlands, Amsterdam
    MS-Off Ver
    Excel 2010
    Posts
    585

    How do I get the value, rather than the formula, in a cell with VBA

    I am inserting this formula in my excel sheet.

    Please Login or Register  to view this content.
    There exists however more than 6000 rows and it takes therefore an awful lot of time to process.
    Is there a way to get the result rather than the formula itself in the cell?
    Last edited by alansidman; 03-12-2021 at 10:37 AM.

  2. #2
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,191

    Re: How do I get the value, rather than the formula, in a cell with VBA

    Untested as no sample file...
    Please Login or Register  to view this content.
    Good Luck
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the star to left of post [Add Reputation]
    Also....add a comment if you like!!!!
    And remember...Mark Thread as Solved.
    Excel Forum Rocks!!!

  3. #3
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,907

    Re: How do I get the value, rather than the formula, in a cell with VBA

    I would suggest COUNTIF would be more efficient unless you have a specific need to avoid it. If you do, then you should try and limit the number of rows used in your range as that is what slows the formula down.
    Rory

  4. #4
    Forum Contributor
    Join Date
    08-19-2009
    Location
    Netherlands, Amsterdam
    MS-Off Ver
    Excel 2010
    Posts
    585

    Re: How do I get the value, rather than the formula, in a cell with VBA

    Hello Sintek,

    Thank you for trying.
    it did not work however.
    It returned #VALUE!

    I enclosed a sample file.
    Attached Files Attached Files
    Last edited by Jonathan78; 03-13-2021 at 02:35 AM.

  5. #5
    Forum Contributor
    Join Date
    08-19-2009
    Location
    Netherlands, Amsterdam
    MS-Off Ver
    Excel 2010
    Posts
    585

    Re: How do I get the value, rather than the formula, in a cell with VBA

    Hello Rorya,
    Most values exceed the 255 character limit.
    SUMPRODUCT seems to be the only one being able to handle this

  6. #6
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,907

    Re: How do I get the value, rather than the formula, in a cell with VBA

    In that case you should try to limit the rows involved in the formula. Your current version has to check every row on the sheet.

  7. #7
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,191

    Re: How do I get the value, rather than the formula, in a cell with VBA

    Apologies...i missed that you were trying to input into range and not individual cell...What are you actually wanting to achieve...The sample file and formula provided has no connection?

  8. #8
    Forum Contributor
    Join Date
    08-19-2009
    Location
    Netherlands, Amsterdam
    MS-Off Ver
    Excel 2010
    Posts
    585

    Re: How do I get the value, rather than the formula, in a cell with VBA

    The formula in the sample file is a little bit different than the previous provided formula because I had to simplify things.
    The idea is the same:

    In sheet "NEW" the result of a formula needs to be inserted in column E.
    The formula checks if the value on sheet "NEW" in column D als exists somewhere in column D on sheet "OLD"
    If it does exists the outcome will be true else it will be false

    Because many cells exceed 255 characters, many formulas will not work like:
    =COUNTIF(range,value)>0.
    =IF(COUNTIF(range,value),"Yes","No")
    =COUNTIF(A1:A100,"*"&C1&"*")>0.
    =ISNUMBER(MATCH(value,range,0))
    etc.

    One that does still work eventhough it exists the 255 character limit is SUMPRODUCT.
    Therefore I would like to use that one.

    Another thing to take into consideration is that my actual file contains thousands of rows.
    So when I insert the formula, rather than the result of the formula, It will take very long to run the macro.

    Therefore I'd like to insert the result value of the SUMPRODUCT formula by means of VBA

  9. #9
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,191

    Re: How do I get the value, rather than the formula, in a cell with VBA

    So...Upload a sample file showing the expected result...manually and I'm sure a solution can be provided...
    Perhaps match formula
    Edit ... my bad only now noticed exceeds 255 characters...match no work
    Last edited by sintek; 03-13-2021 at 02:57 AM.

  10. #10
    Forum Contributor
    Join Date
    08-19-2009
    Location
    Netherlands, Amsterdam
    MS-Off Ver
    Excel 2010
    Posts
    585

    Re: How do I get the value, rather than the formula, in a cell with VBA

    I enclosed a new file with the desired outcome:


    So the fllowing gives me the desired outcome, but is inserted as a formula, rather than the outcome of a formula and therefore having a long runtime
    Please Login or Register  to view this content.
    This is what I have tried so far, but is returning #VALUE!, so I must be doing something wrong here
    Please Login or Register  to view this content.
    Attached Files Attached Files

  11. #11
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,518

    Re: How do I get the value, rather than the formula, in a cell with VBA

    Please Login or Register  to view this content.

  12. #12
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,191

    Re: How do I get the value, rather than the formula, in a cell with VBA

    Yep...Dictionary to the rescue...

  13. #13
    Forum Contributor
    Join Date
    08-19-2009
    Location
    Netherlands, Amsterdam
    MS-Off Ver
    Excel 2010
    Posts
    585

    Re: How do I get the value, rather than the formula, in a cell with VBA

    Hello Jindon,
    Thank you for trying, but looping is not an option.
    My workbook contains thousands of rows.
    I already tried looping but takes ages to run.

  14. #14
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,518

    Re: How do I get the value, rather than the formula, in a cell with VBA

    Did you actually teste the code?

    Calculating such bulk data with CountIf/Sumproduct takes ages, but the array and the dictionary is the best.

    And you should forget the myth about the LOOP.
    Loop is very fast. It depends on how you use it.
    Last edited by jindon; 03-13-2021 at 03:36 AM.

  15. #15
    Forum Contributor
    Join Date
    08-19-2009
    Location
    Netherlands, Amsterdam
    MS-Off Ver
    Excel 2010
    Posts
    585

    Re: How do I get the value, rather than the formula, in a cell with VBA

    Thanks again Jindon!
    I turned out to be must faster than expected.

+ 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. [SOLVED] Help Copying Formula from another cell, modifying formula and then pasting to new cell
    By TygerG in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-05-2021, 02:05 PM
  2. Replies: 8
    Last Post: 11-29-2017, 12:36 PM
  3. [SOLVED] If cell has a formula, copy text to TextBox and leave formula unchanged in cell
    By yachrishere in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-01-2016, 06:26 PM
  4. Replies: 3
    Last Post: 07-14-2016, 03:53 PM
  5. [SOLVED] Formula to return Blank cell if referenced cell has no entries, if not use formula
    By stpeter in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 02-17-2016, 01:41 PM
  6. [SOLVED] Enter formula result from one cell into a COUNTIF formula in another cell. Help please!
    By gregrach in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 04-10-2014, 11:23 AM
  7. Replies: 5
    Last Post: 05-07-2013, 08:34 AM

Tags for this Thread

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