+ Reply to Thread
Results 1 to 2 of 2

How to enter a formula into a cell after a macro runs

  1. #1
    Forum Contributor
    Join Date
    07-01-2010
    Location
    Niles, Michigan
    MS-Off Ver
    Excel 2010
    Posts
    137

    How to enter a formula into a cell after a macro runs

    Ok so I have this sheet that when a command button is pressed by the user it takes some cell values and paste them into another sheet. It then clears all the data in cells that are specified and then hides rows for the user to start over. There are some cells that have formulas in them that could be over written by the user if need be. These cells are C132, C133 and C134. Below are the formulas in these cells.
    C132 formula is =IF(ISBLANK(C123),"",$Q$109+$Q$94+$Q$79+$Q$64+$Q$49+$Q$34+$Q$19+$Q$4)
    C133 formula is =IF(ISBLANK(C123),"",IF(COUNT($W$109,$W$94,$W$79,$W$64,$W$49,$W$34,$W$19,$W$4)>0,SUM($W$4,$W$19,$W$34,$W$49,$W$64,$W$79,$W$94,$W$109),""))
    C134 formula is =IF(AND(C125="",C123=""),"",IFERROR(SUM($V:$V)/(COUNT($V:$V)-COUNTIF($V:$V,0)),0))

    What I want to happen is after the command button is pressed, I'd like to put these formulas back into the cells where they belong. If the user has changed the cells and manually put in a value.

    The code for the command button is this.
    Please Login or Register  to view this content.
    Thanks in advance for everything
    excel 2010

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

    Re: How to enter a formula into a cell after a macro runs

    You should record yourself putting these formulae into the cells

    Stop the Macro recorder and then add the code to your macro

    This is what I recorded I obviously put the formulae in any old cell


    Please Login or Register  to view this content.

    I then edit the above code

    Please Login or Register  to view this content.
    Last edited by mehmetcik; 11-11-2015 at 02:21 PM.
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

+ 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] Trouble with sub that runs on pressing enter after modifying cell's content
    By luv2glyd in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-09-2014, 04:49 PM
  2. Macro won't enter complex formula in selected cell.
    By Fungijus in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-03-2013, 09:10 AM
  3. Unlocking Cell after Macro Runs
    By brittm in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-17-2009, 12:37 PM
  4. Don't select a cell after macro runs ???
    By richardeallen in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-03-2008, 11:16 AM
  5. Change cell value and macro runs
    By Macdave_19 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-23-2007, 04:18 AM
  6. Cell value change runs a macro?
    By Steach91 in forum Excel General
    Replies: 6
    Last Post: 06-18-2006, 03:20 PM
  7. macro runs if I Clear a cell
    By Nimzow in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-20-2005, 11:06 AM
  8. [SOLVED] Can you enter a formula in a cell to run a macro?
    By Nevaeh in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 02-14-2005, 08:06 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