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.
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
I actually use a UDF for this, also then in conjunction with an INDIRECT() formula. Here's the UDF:
How to install the User Defined Function:Function Previous() 'Returns the name of the previous sheet as =Previous() Previous = Worksheets(Application.Caller.Parent.Index - 1).Name End 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 theicon 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!)
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)
My Recommended Reading:
Volatility
Sumproduct & Arrays
Pivot Intro
Email from XL - VBA & Outlook VBA
Function Dictionary & Function Translations
Dynamic Named Ranges
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
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks