+ Reply to Thread
Results 1 to 8 of 8

Restoring original formula by VBA

  1. #1
    Forum Contributor
    Join Date
    11-14-2007
    Posts
    142

    Restoring original formula by VBA

    Hi all.

    I have workbook that contains several hidden worksheets that are used as templates and several visible worksheets that are copies of those templates.

    Each visible worksheet contains a cell H2 which contains a text string which is the name of the original hidden template worksheet from which that sheet was created. Each visible worksheet also has a localised defined name "MasterSheet" which refers to cell $H$2 in that worksheet.

    I am trying to write a macro that has the following effect:

    Reset the formulae contained in any selected range of cells to be the original formulae that resided in those cells when the active worksheet was originally created. These formulae will be the same as the formulae contained in the same cell references of the corresponding hidden template worksheet. (no insertion or deletion of rows or columns is permitted)

    Cells may contain single-cell array formulae but not multi-cell array formulae

    This is what I have come up with so far:

    Please Login or Register  to view this content.
    As far as I can tell I have two problems:
    1) What is the correct syntax of the WITH statement so that it refers to the worksheet described by the defined name "MasterSheet"?

    2) How to I define the value of stFormula preparatory to resetting the relevant cells?

    Of course there may be something else that I have missed.

    Any help appreciated.
    Last edited by 1eyedjack; 02-21-2010 at 05:52 PM.

  2. #2
    Valued Forum Contributor JeanRage's Avatar
    Join Date
    03-02-2009
    Location
    Nice, France
    MS-Off Ver
    Excel 2003
    Posts
    705

    Re: Restoring original formula by VBA

    Hi,

    Have you tried :
    With ThisWorkbook.Worksheets("MasterSheet")
    HTH

  3. #3
    Forum Contributor
    Join Date
    11-14-2007
    Posts
    142

    Re: Restoring original formula by VBA

    I think I have a partial solution:
    Please Login or Register  to view this content.
    I just wish I could think of a simple way of setting stWSName by reference to the defined name "MasterSheets"

  4. #4
    Forum Contributor
    Join Date
    11-14-2007
    Posts
    142

    Re: Restoring original formula by VBA

    Sorry my last post crossed over with JeanRage. I will try that thank you

  5. #5
    Forum Contributor
    Join Date
    11-14-2007
    Posts
    142

    Re: Restoring original formula by VBA

    Quote Originally Posted by JeanRage View Post
    Hi,

    Have you tried :


    HTH
    Sorry that did not work (error 9 subscript out of range). To be frank I did not expect it to. The value of "MasterSheets" is not the name of a worksheet but the reference to a cell within ActiveSheet that contains that name. I tried toying around with putting variations of
    Application.Indirect(MasterSheets)
    into the code but couldn't get that to work. Indeed I could not get VBA to recognise Application.Indirect() as a valid function at all.

  6. #6
    Forum Contributor
    Join Date
    11-14-2007
    Posts
    142

    Re: Restoring original formula by VBA

    OK I think I have it sussed now.
    I should be using
    Please Login or Register  to view this content.
    to get the value of the cell to which the name "MasterSheet" refers, where all along I had been using
    Please Login or Register  to view this content.
    which only returns the cell reference.

  7. #7
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Restoring original formula by VBA

    Here's another way (minimally tested):
    Please Login or Register  to view this content.
    Entia non sunt multiplicanda sine necessitate

  8. #8
    Forum Contributor
    Join Date
    11-14-2007
    Posts
    142

    Re: Restoring original formula by VBA

    Ah thanks for that suggestion. It will take a few moments for me to digest and understand it, but looks good.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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