+ Reply to Thread
Results 1 to 2 of 2

Thread: How to write a formula which accesses the just previous sheet

  1. #1
    Registered User
    Join Date
    02-01-2012
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    2

    How to write a formula which accesses the just previous sheet

    Hello,

    I have an excel workbook 2010, in which i have a number of sheets.
    In each sheet, I have the results of a particular test run and the analysis.
    Now, for the analysis, I need to do a diff of the number of test-cases passed in the current run (Current Sheet) and the number of test-cases passed in the previous run (previous sheet).
    And this formula I need for all the sheets.

    Thus, how do I have a formula in which I do a diff of a value of the current sheet and the previous sheet.
    I case of just two sheets (sheet1 and sheet2), if I have to do a diff on sheet2 then the formula is :
    =B4-'sheet1'!B4
    But this is when my sheet names are constant, but I need the formula such that for each new sheet, the formula picks the value from the previous sheet only.

    Could someone please help me with this?
    Also, I do not know how to create macros in excel, so if you provide the code for a new macro, I would be grateful if you could explain how to use/apply it also.

    Thanks and regards,
    Sunny

  2. #2
    Valued Forum Contributor smuzoen's Avatar
    Join Date
    10-28-2011
    Location
    Brisbane, Australia
    MS-Off Ver
    Excel 2003/2007/2010
    Posts
    359

    Re: How to write a formula which accesses the just previous sheet

    I think this is what you are after - I have attached a sample workbook with values in B4 and I am placing the formula of (current sheet b4 - previous sheet B4) into cell C5 - I have made the sheets not just Sheet 1, Sheet 2 etc - so this should work no matter what the worksheet is called. You could run this macro when you need to add the formulas to the sheets. To get to the code open the workbook and hit ALT F11 and this will take you to the VB Editor. The code is inside Module 1 - double click on Module 1 to see the code. Close the VB Editor once you have had a look at the code in the module. When you are back to the workbook to run the macro you need to select macros from the Developer tab in the workbook or hit ALT F8 and this will bring up a list of available macros to run - select macro called addFormula to run the macro.
    Let me know if it does what you are after or need further help.
    Here is a link to more information about macros http://office.microsoft.com/en-us/ex...010014113.aspx
    Sub addFormula()
    Dim ws As Worksheet, wsPr As String, x As Long
    For Each ws In ActiveWorkbook.Worksheets
    If x > 0 Then
    ws.Range("C5").Formula = "=B4-" & wsPr & "!B4"
    End If
    x = x + 1
    wsPr = ws.Name
    Next
    End Sub
    Hope this helps.
    Anthony
    “Confidence never comes from having all the answers; it comes from being open to all the questions.”
    PS: Remember to mark your questions as Solved once you are satisfied and rate the answer(s) questions.”
    Attached Files Attached Files
    Last edited by smuzoen; 02-03-2012 at 06:38 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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.2.0