Welcome toExcel.Tips.Net
Tips.Net Home
ExcelTips Home
Ask an Excel Question
Make a Comment
ExcelTips FAQ
ExcelTips Premium
Learn Access Now
Free Printable Forms
Beauty Tips
Car Tips
Cleaning Tips
College Tips
Cooking Tips
Excel2007 Tips
ExcelTips
Family Tips
Gardening Tips
Health Tips
Home Tips
Legal Tips
Money Tips
Organizing Tips
Pest Tips
Pet Tips
Wedding Tips
Word2007 Tips
WordTips
Advertise on the
ExcelTips Site
Adding a Little Animation to Your Life
Converting a Range of URLs to Hyperlinks
Making the Formula Bar Persistent
Anita has a worksheet with over 10,000 rows. Each row represent an individual contract. Each contract has a start date (column A) and an end date (column B). She needs a way to list in columns C, D, E, etc. the individual months covered by the contract. For instance, if column A contains 01 July 2009 and column B contains 30 September 2009, she needs column C to contain Jul 09, column D to contain Aug 09, and column E to contain Sep 09. Whatever formulas are used need to accommodate contract lengths that may be quite different.
There are several ways to go about such a task. It is possible to use some intermediate columns that specify things like the starting month and the number of months of each contract, but it turns out that such intermediate columns are not necessary. For instance, assuming that your contracts start in row 2, you could place the following formula in cell C2:
=TEXT(A2,"mmm yy")
Then, beginning in cell D2 you could place this formula:
=IF(DATE(YEAR($A2),MONTH($A2)+COLUMNS($D2:D2), DAY($A2))>$B2,"",TEXT(DATE(YEAR($A2),MONTH($A2) +COLUMNS($D2:D2),DAY($A2)),"mmm yy"))
This is one formula, and it uses the position of the cells containing the formula, along with the contract starting date, to calculate, basically, the month of offset from that starting month. The formula can be copied toward the right (columns E, F, G, etc.) for as far as necessary to display all the months and years.
The one drawback to the formula is that if the contract ending date is earlier in the month than the contract starting date, then the last month is not displayed. Thus, if the contract starts on 12 June 2009 and it ends on 05 February 2010, then the last month (February) will not be displayed by the formula. You could, instead, use the following formula in cell C2 and copy it to the right as far as necessary:
=IF(DATE(YEAR($A2),MONTH($A2)+COLUMN()-2,0) >DATE(YEAR($A2),MONTH($B2)+1,0),"",TEXT(DATE (YEAR($A2),MONTH($A2)+COLUMN()-2,0),"mmm yy"))
This formula also relies on the columns in which it resides, using them to calculate an offset from the contract start date. The formula will work just fine, regardless of the relationship between the contract start and end dates.
If you don't want to rely on column positioning, there is another approach you can take. Place the following formula in cell C2:
=(A2)
Then, in cell D2 place the following formula:
=IF($B2>C2,EOMONTH(C2,1),"")
Copy the formula in D2 to the right as many cells as necessary, and then format all those cells (including C2 and D2) as dates that display only the month and year. The formula will look at B2 (the contract ending date) to see if it is larger than C2. If it is, then the formula returns the serial number of the last day of the next month in series. If it is not, then a blank ("") is returned.
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (5406) applies to Microsoft Excel versions: 97 2000 2002 2003 2007
Make Home Buying Less Stressful! Why make home buying harder than it needs to be? Put your mind at ease—discover all the questions you need to ask to make the best buying decision.