+ Reply to Thread
Results 1 to 17 of 17

Restore formulas macro

  1. #1
    Forum Contributor
    Join Date
    08-25-2014
    Location
    Pennsylvania, US
    MS-Off Ver
    Windows '16
    Posts
    165

    Restore formulas macro

    Hey guys, I need a (fairly simple methinks) macro to restore formulas in a range upon a button press. The formulas will be overwritten by the user, but eventually will need to be restored. See the attached workbook and please let me know if you have any questions.

    Thanks in advance!

    Restore formula problem.xlsx

  2. #2
    Forum Expert ben_hensel's Avatar
    Join Date
    01-26-2012
    Location
    Northeast USA
    MS-Off Ver
    Office 365
    Posts
    2,043

    Re: Restore formulas macro

    I would just use MacroRecorder to record myself manually fixing the table, and then bind the recorded macro to the button.
    Click the [* Add Reputation] Button to thank people for help!
    Post Attachment: Click [Go Advanced] under the reply box; then click [Manage Attachments] to launch the attachments dialogue.
    Mark Thread Solved: Go to the top of the first post; Select [Thread Tools] dropdown; Pick the [Mark thread as Solved] option.

  3. #3
    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
    44,485

    Re: Restore formulas macro

    Please Login or Register  to view this content.

    Regards, TMS
    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


  4. #4
    Forum Contributor
    Join Date
    08-25-2014
    Location
    Pennsylvania, US
    MS-Off Ver
    Windows '16
    Posts
    165

    Re: Restore formulas macro

    Thanks to both of you. I got both methods to work, but I just realized my real situation is more complicated. The formulas are array formulas - and not ones that are linked. So Range("C4:C" & lLR).FormulaArray won't work for me because it makes a set of cells that can't be individually edited.

    Can you alter the macro to insert array formulas that are not linked? Thanks!

  5. #5
    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
    44,485

    Re: Restore formulas macro

    Please Login or Register  to view this content.

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

    Re: Restore formulas macro

    Just use copy and paste - as long as the formula in C4 is intact:

    Range("C4").Copy Range("C4:C" & lLR)
    Bernie Deitrick
    Excel MVP 2000-2010

  7. #7
    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
    44,485

    Re: Restore formulas macro

    If you use
    Please Login or Register  to view this content.
    it will fail because you can't change part of an array.

    If you use
    Please Login or Register  to view this content.
    it will work but it will copy the cell formatting, including the borders.

  8. #8
    Forum Contributor
    Join Date
    08-25-2014
    Location
    Pennsylvania, US
    MS-Off Ver
    Windows '16
    Posts
    165

    Re: Restore formulas macro

    Thanks guys. TMS, how would you repeat this across a number of sheets? For example restore formulas on Sheet1, Sheet2, Sheet3, etc. The exact same formula, and the same range on each sheet?

    Bernie, how do you modify that to just copy formulas? (I'm getting formatting copied...). EDIT: Nevermind, based on TMS's comment I don't think that will work.

    Thanks

  9. #9
    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
    44,485

    Re: Restore formulas macro

    See post #5 and post #7

  10. #10
    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
    44,485

    Re: Restore formulas macro

    I love it when the goal posts start to move ...

  11. #11
    Forum Contributor
    Join Date
    08-25-2014
    Location
    Pennsylvania, US
    MS-Off Ver
    Windows '16
    Posts
    165

    Re: Restore formulas macro

    ??? I really don't know any VBA but I don't think the post #5 is going to work across numerous sheets. Or #7...


    Thanks though +1.

  12. #12
    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
    44,485

    Re: Restore formulas macro

    ... but I don't think the post #5 is going to work across numerous sheets
    No, it wasn't designed to. When you started the thread, it was a simple formula being inserted into a range of cells on a single sheet. It's late now, I'll look again tomorrow.

    Thanks for the rep.

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

    Re: Restore formulas macro

    If you have specific sheets, with the same source cell:

    Please Login or Register  to view this content.
    If you want to do all sheets, with the same source cells

    Please Login or Register  to view this content.

  14. #14
    Forum Contributor
    Join Date
    08-25-2014
    Location
    Pennsylvania, US
    MS-Off Ver
    Windows '16
    Posts
    165

    Re: Restore formulas macro

    Alright thanks TMS and Bernie - and sorry for moving the goalposts!

  15. #15
    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
    44,485

    Re: Restore formulas macro

    You're welcome. Thanks for the rep.

    No worries about the goalposts I just tend to highlight it so people are aware that it is often better to think through their actual and total requirement ... and post a sample workbook that truly reflects the final outcome.


    I thought I had posted this earlier, but, apparently not. Not sure what happened there. And, what was worse, I hadn't saved a copy

    Anyway, here it is for completeness:

    Please Login or Register  to view this content.
    See the updated sample workbook.

    Regards, TMS
    Attached Files Attached Files

  16. #16
    Forum Contributor
    Join Date
    08-25-2014
    Location
    Pennsylvania, US
    MS-Off Ver
    Windows '16
    Posts
    165

    Re: Restore formulas macro

    Great - thank you for posting that. I'm beginning to learn VBA and it's great to see all the ways you can skin a cat – and compare the logic behind them. Again, thanks for following up TMS.

  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
    44,485

    Re: Restore formulas macro

    You're very welcome. Enjoy

+ 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. Macro for Excel session restore
    By sonofamonkey10 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-23-2015, 05:35 PM
  2. Restore data after running a specific macro
    By YasserKhalil in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 01-03-2015, 12:41 PM
  3. Replies: 5
    Last Post: 09-25-2013, 02:51 PM
  4. canceled and restore arrows are grayed out in Excel with this macro
    By gibtoul in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 07-31-2013, 11:32 AM
  5. Replies: 0
    Last Post: 08-08-2012, 09:29 PM
  6. Help modifying macro to wrap iferror formulas around existing formulas
    By dcgrove in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-14-2012, 02:04 PM
  7. How to restore pre-macro values?
    By minerva87 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-02-2010, 09:46 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