Increment Date Until

ncalenti

New Member
Joined
Aug 12, 2011
Messages
39
Here is something tricky I am trying to implement without VBA if possible.

So I have 2 dates and a number of months.
Ex
D1 = 4/1/2006
D2 = 5/1/2009
Months = 18

Here is the algorithm in english:
Do until D1>=D2:
1. Add Number of months to D1
2. After that, keep incrementing D1 by a year

So running through the example:
Step 1 : Get D1 - 4/1/2006
2: Add Months to it - 4/1/2006 + 18 months = 10/1/2007
3: Test 10/1/2007 >= 5/1/2009 = False.
4: Add 1 year onto 10/1/2007 = 10/1/2008
5. Still not >= 5/1/2009
6. Add another year = 10/1/2009
7. Now it bigger so return 10/1/2009

From an efficiency standpoint, keep in mind calc needs to run on > 300k rows
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
ncalenti,

=IF(A2<B2,MONTH(A2)+MOD(C2,12)&"/"&DAY(A2)&"/"&YEAR(A2)+YEAR(B2)-YEAR(A2)+INT(C2/12),B2)
Give the below formula a try. Notes:I assumed there were headers, so data and formula start on row 2
A2 = Date1
B2 = Date2
C2 = Months


=IF(A2<B2,MONTH(A2)+MOD(C2,12)&AMP;" p ?&YEAR(A2)+YEAR(B2)-YEAR(A2)+INT(C2 ?&DAY(A2)&? 12),B2)<>
Hope that helps,
~tigeravatar
 
Last edited:
Upvote 0
Weird, the only way I could get it to post was to put spaces around the < symbol. So make sure to take those spaces out:

=if(a2 < b2,month(a2)+mod(c2,12)&"/"&day(a2)&"/"&year(a2)+year(b2)-year(a2)+int(c2/12),b2)
 
Upvote 0
another note: Seeing as its friday, and I want to get this done, if anyone has a VBA solution, I am all ears!
 
Upvote 0
D3 holds Months in the sample formula

=EDATE(D1,CEILING(DATEDIF(D1,D2,"M")-D3,12)+D3)
 
Upvote 0

Forum statistics

Threads
1,224,517
Messages
6,179,242
Members
452,898
Latest member
Capolavoro009

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top