+ Reply to Thread
Results 1 to 6 of 6

Need to have result from a formula in one cell appear in another cell...

  1. #1
    Registered User
    Join Date
    08-06-2014
    Location
    Tucson, Arizona
    MS-Off Ver
    XP
    Posts
    43

    Need to have result from a formula in one cell appear in another cell...

    I have a formula in A1 (it references about 100 different cells), and I'd like the result of A1 to appear in A2 without A2 containing a formula.

    There might be a REALLY simple solution to this though without reading the stuff below. I'm not opposed to locking A2, but when I do that, somehow the ability to copy the contents in A2 doesn't work. Maybe it's because I have checkboxes on my spreadsheet or there's a macro... I have no idea. But if there were a way to copy the results from A2 while that cell is locked, then that is all I would need. I could unlock that cell, but then there's the problem of the formula appearing if you double click the cell, and then all the stuff below...

    If I can't copy the contents of a locked then, then I could unlock the cell and use the following macro, but then that creates other problems....

    Here's the macro:

    Private Sub Worksheet_Change (ByVal Target As Range)
    Range("CellWithValue").Value = Range("CellWithFormula").Value
    End Sub


    In theory, this code works great because any time there is a change to the worksheet, the output in A2 always updates. Here's is my problem... I have a command button macro which deletes about 200 fields on the worksheet when clicked, but when I use the code above, it takes a while for all the fields to be cleared because every time a field is cleared it counts as a change and then the code above runs 200 times, which in turn increases the time it takes for the command button to run and clear all the fields.

    So I need a macro or something that hardcodes the results in A1 to A2, and it must be dynamic so that if there is a change on the worksheet, A2 is updated, BUT I want to keep my "clear all fields" command button without it running so slowly.

    Here's my idea: if you click on the "clear all" command button, it clears all fields, but only the last field cleared is identified by the code above as a change. So the "clear all" button clears all fields, and isn't slowed down by the code above.

    Any idea on how to do that?
    Last edited by danielneedssomehelp; 08-06-2014 at 05:44 PM.

  2. #2
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Need to have result from a formula in one cell appear in another cell...

    You could use Application.EnableEvents = False before the code runs and Application.EnableEvents = True after the code runs where you want to trigger a change.

  3. #3
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Need to have result from a formula in one cell appear in another cell...

    Use Application.Enable Events = False as described above.

    It will stop a change triggering another loop.

    If that doesn't work for you, [ Sometimes I only want to stop specific events ] then declare a global variable and use that to control your macro.

    Please Login or Register  to view this content.

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    08-06-2014
    Location
    Tucson, Arizona
    MS-Off Ver
    XP
    Posts
    43

    Re: Need to have result from a formula in one cell appear in another cell...

    Thank you--- I think I'm getting close, just need a little code placement help.

    My original code that erased all my checkboxes and desired cells is this:

    Private Sub CommandButton1_Click()

    ActiveSheet.Shapes(8).ControlFormat.Value = False
    ActiveSheet.Shapes(9).ControlFormat.Value = False
    ActiveSheet.Shapes(10).ControlFormat.Value = False
    ActiveSheet.Shapes(11).ControlFormat.Value = False
    ActiveSheet.Shapes(12).ControlFormat.Value = False
    ActiveSheet.Shapes(13).ControlFormat.Value = False
    ActiveSheet.Shapes(14).ControlFormat.Value = False
    ActiveSheet.Shapes(15).ControlFormat.Value = False
    ActiveSheet.Shapes(16).ControlFormat.Value = False
    ActiveSheet.Shapes(17).ControlFormat.Value = False
    ActiveSheet.Shapes(18).ControlFormat.Value = False
    ActiveSheet.Shapes(20).ControlFormat.Value = False
    Range("Q7:Q42").Select
    Selection.ClearContents
    Range("O7:O42").Select
    Selection.ClearContents
    Range("J7:J42").Select
    Selection.ClearContents
    Range("H7:H42").Select
    Selection.ClearContents
    Range("C12:C13").Select
    Selection.ClearContents
    Range("C10").Select
    Selection.ClearContents
    End Sub


    Directly after that, I added:

    Private Sub Worksheet_Change(ByVal Target As Range)
    Range("$A$2").Value = Range("$A$1").Value
    End Sub


    Where should I put the Application.EnableEvents = False and Application.EnableEvents = True?

    Also, if that doesn't work, where should I put the Public Changeflag as Integer and

    Private Sub Worksheet_Change (ByVal Target As Range)
    If Changeflag = 1 then exit sub
    Changeflag =1
    Range("CellWithValue").Value = Range("CellWithFormula").Value
    Changeflag = 0
    End Sub


    And if I add the Public Changeflag as Integer code, would I not need the Application.Enable Events = False code?

    Thank you!

  5. #5
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Need to have result from a formula in one cell appear in another cell...

    Please use code tags. Here is your answer:

    Please Login or Register  to view this content.
    With that being said. Why don't you just combine the 2 codes so that after Range("C10") is cleared you then set Range("A2") = Range("A1") ?

  6. #6
    Registered User
    Join Date
    08-06-2014
    Location
    Tucson, Arizona
    MS-Off Ver
    XP
    Posts
    43

    Re: Need to have result from a formula in one cell appear in another cell...

    Well, I wanted the content in A2 or A1 to be updated as users input data. When I combine the two codes, that doesn't happen. When I leave the codes separate, it works, but after adding some data into the fields referred to in the code above, Excel freezers up and crashes. You know, I could probably avoid all of this if I could just copy the text from A2 when that cell is locked, but for some reason, I cannot copy any locked cell on this spreadsheet and I think it has to do with the checkboxes I added.

+ 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] Conditional format a cell based on a result of a formula in another cell
    By Taiter in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 06-20-2013, 04:45 PM
  2. [SOLVED] Conditional format a cell based on a result of a formula in another cell
    By Taiter in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 06-20-2013, 01:47 PM
  3. [SOLVED] Code to delete cell contents IF the result of a formula in the cell = 0
    By jayjaynz in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-22-2013, 03:58 AM
  4. Replies: 6
    Last Post: 09-16-2010, 05:19 AM
  5. Advanced formula - Return result & Show Cell Reference of result
    By Irv in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 05-05-2006, 10:40 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