Friday, September 28, 2018

Excel - automatically fill down a row with date range matching a specific pattern


Given a specific start date (say Jan, 11th 2012 for example), I want to fill down a row in excel automatically with a date range matching the following pattern for the days (bi-monthly pay period).


1. 11th - 25th
2. 26th - 10th

Of course with actual dates in each cell including the month and year (not simply repeating the two values above). What I'm looking for is a way to put in one or two specific date ranges, such as:


January 11th, 2012 - January 25th, 2012
January 26th, 2012 - February 10th, 2012

And have excel automatically fill down many more cells in the same pattern:


January 11th, 2012 - January 25th, 2012
January 26th, 2012 - February 10th, 2012
February 11th, 2012 - February 25th, 2012
....
December 11th, 2012 - December 25th, 2012

How can I do this?


Answer



Format your columns to the date format you prefer. Enter the date of 1/11/2012 into cell A1 and the date of 1/25/2012 in cell B2. Copy the following code into A2;


=DATE(YEAR(B1),MONTH(B1), DAY(B1)+1)

and copy this into B2;


=IF(DAY(B1)=10, DATE(YEAR(B1), MONTH(B1), DAY(25)), DATE(YEAR(B1),MONTH(B1)+1, DAY(10)))

Go ahead and highlight A2 and B2 to drag them down as far as you need.


Should look like this when done;


Screen Shot


No comments:

Post a Comment

hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...