+ Reply to Thread
Results 1 to 5 of 5

Thread: Getting data from previous months

  1. #1
    Registered User
    Join Date
    09-02-2009
    Location
    Singapore
    MS-Off Ver
    Excel 2003
    Posts
    44

    Getting data from previous months

    I worksheets made for each month but I require the current sheet to always acquire the worksheet of the previous month. how to I go about doing it?Eg.

    "Dec09" to get data from "Nov09" and "Nov09" to get data from "Oct09"
    Last edited by gloom52; 09-21-2009 at 06:18 AM.

  2. #2
    Forum Guru martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    10,798

    Re: Getting data from previous months

    one way
    =INDIRECT(TEXT(EOMONTH(TODAY(),-1),"mmmyy")&"!A1") but it would probably be better to put =today() in a spare cell and reference that
    =INDIRECT(TEXT(EOMONTH(B1,-1),"mmmyy")&"!A1") where B1 =today()
    you need to activate the analysis tool pack to use eomonth function
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and a dabbler in Cisco
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  3. #3
    Forum Guru JBeaucaire's Avatar
    Join Date
    03-21-2008
    Location
    Bakersfield, CA
    MS-Off Ver
    2010
    Posts
    19,224

    Re: Getting data from previous months

    I actually use a UDF for this, also then in conjunction with an INDIRECT() formula. Here's the UDF:

    Function Previous()
    'Returns the name of the previous sheet as   =Previous()
        Previous = Worksheets(Application.Caller.Parent.Index - 1).Name
    End Function
    How to install the User Defined Function:

    1. Open up your workbook
    2. Get into VB Editor (Press Alt+F11)
    3. Insert a new module (Insert > Module)
    4. Copy and Paste in your code (given above)
    5. Get out of VBA (Press Alt+Q)
    6. Save your sheet

    The function is installed and ready to use.

    ========
    On sheet2, you would normally put this in to get cell A1 from the prior sheet:
    =Sheet1!A1

    Now you can use this instead:
    =INDIRECT("'" & PREVIOUS() & "'!A1")

    This formula would always grab cell A1 from the previous sheet, whatever it is called.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    “None of us is as good as all of us” - Ray Kroc
    “Actually, I *am* a rocket scientist.” - JB (little ones count!)

  4. #4
    Forum Moderator DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Suffolk, UK
    MS-Off Ver
    2002, 2007 & 2010
    Posts
    21,423

    Re: Getting data from previous months

    On the off chance you have morefunc.xll installed see also SHEETOFFSET function, like JB's UDF this assumes you are are listing your sheets in sequential order - if not then you need to use Martin's approach.

    Beware of course that INDIRECT is Volatile (see link in sig. for more info)

  5. #5
    Registered User
    Join Date
    09-02-2009
    Location
    Singapore
    MS-Off Ver
    Excel 2003
    Posts
    44

    Re: Getting data from previous months

    Thats great guys. The formula is working wonders. Now I do not have to go through all the sheets to slowly change each individual months. Cheers

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