+ Reply to Thread
Results 1 to 8 of 8

Trying to replace cell formula with just its value after the calculation is complete

Hybrid View

  1. #1
    Registered User
    Join Date
    08-19-2021
    Location
    pittsburgh
    MS-Off Ver
    2017
    Posts
    4

    Trying to replace cell formula with just its value after the calculation is complete

    Hi, I am trying to create a function that I can use on any cell in my workbook. I want it to essentially copy the cell and paste special the value back into the same cell. I am trying to do so with the following code but its not working:

    Function PasteValue()
    
    Range(ActiveCell).Copy
    Range(ActiveCell).PasteSpecial xlPasteValues
    
    End Function
    Any help would be appreciated, thanks!
    Last edited by ashriva1; 08-19-2021 at 11:27 AM.

  2. #2
    Forum Expert sweep's Avatar
    Join Date
    04-03-2007
    Location
    Great Sankey, Warrington, UK
    MS-Off Ver
    2003 / 2007 / 2010 / 2016 / 365
    Posts
    3,446

    Re: Trying to replace cell formula with just its value after the calculation is complete

    Hi,

    How about this?

    ActiveCell.Value = ActiveCell.Value
    Rule 1: Never merge cells
    Rule 2: See rule 1

    "Tomorrow I'm going to be famous. All I need is a tennis racket and a hat".

  3. #3
    Registered User
    Join Date
    08-19-2021
    Location
    pittsburgh
    MS-Off Ver
    2017
    Posts
    4

    Re: Trying to replace cell formula with just its value after the calculation is complete

    Oh yeah that's much simpler, thank you!

  4. #4
    Registered User
    Join Date
    08-19-2021
    Location
    pittsburgh
    MS-Off Ver
    2017
    Posts
    4

    Re: Trying to replace cell formula with just its value after the calculation is complete

    Actually I realized I worded my question kind of incorrectly. I want to create a converter function that I can use in some cells.

    For example cell A3 = ConverterFunction(A1+A2)

    This would leave me just the value of the formula instead of the formula in the cell itself. When I tried using this function with the ActiveCell property it just gives me a value error.

  5. #5
    Forum Expert sweep's Avatar
    Join Date
    04-03-2007
    Location
    Great Sankey, Warrington, UK
    MS-Off Ver
    2003 / 2007 / 2010 / 2016 / 365
    Posts
    3,446

    Re: Trying to replace cell formula with just its value after the calculation is complete

    OK, that's a little more difficult. A customer function (UDF) works the same as any other function - it will stay present in the cell until you write over it as we've discussed above.

    If you need just values in specific cells you could maybe use a worksheet_change event to drive a macro to do this for you. Are there specific cells that need this treatment?

  6. #6
    Registered User
    Join Date
    08-19-2021
    Location
    pittsburgh
    MS-Off Ver
    2017
    Posts
    4

    Re: Trying to replace cell formula with just its value after the calculation is complete

    The cells that need this function will change each month, and I don't want to my entire workbook to change into values because I still need formulas for other functions.

  7. #7
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,545

    Re: Trying to replace cell formula with just its value after the calculation is complete

    Sub Maybe
    Dim c As Range
        For Each c In ActiveSheet.Range("A1:I50").SpecialCells(xlCellTypeFormulas)    '<---- Change range as required.
            c.Value = c.Value
        Next c
    End Sub
    Or you can use Union for non adjacent cells

    Change cell references as required.
    Sub With_Union()
        With Application.Union(Range("C5"), Range("D6"), Range("E7"))
            .Value = .Value
        End With
    End Sub
    Last edited by jolivanes; 08-19-2021 at 05:45 PM.

  8. #8
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,545

    Re: Trying to replace cell formula with just its value after the calculation is complete

    The previous "With_Union" suggestion does not work.
    Change the Ranges as required.
    Sub With_Union()
    Dim c As Range
        For Each c In Application.Union(Range("C5"), Range("D6"), Range("E7"))
            c.Value = c.Value
        Next c
    End Sub

+ 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. Replies: 1
    Last Post: 11-26-2020, 04:31 PM
  2. Replies: 0
    Last Post: 11-26-2020, 04:27 PM
  3. VBA code to replace sumproduct formula for faster calculation
    By chiidzzz in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-21-2017, 08:24 AM
  4. [SOLVED] Need help with VBA code to perform a calculation, replace cell content and delete row
    By Ellen 2Excel in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-26-2013, 07:13 PM
  5. If cell = "string" then complete a calculation
    By Waggy in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 05-09-2013, 12:45 PM
  6. Complete a calculation only if cell value is up to 100
    By Antonia in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 03-19-2010, 04:41 PM
  7. [SOLVED] Calculation to replace the cell contents
    By Dave Neve in forum Excel General
    Replies: 3
    Last Post: 06-13-2006, 08:15 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