MrPink1986

Active Member
Joined
May 1, 2012
Messages
252
Hi,

I have a date which I will need to increment the date by a day, month or year from the actual date. This is based of a list of fields below and is different per the input. Also each resultant date has to be a business day i.e not a weekend day or a bank holiday. I will forgo the Bank Holiday requirement now.

I am using the formula - =DATE(YEAR($A$1),MONTH($A$1),DAY($A$1)) and hard coding the increment value in each row based of the value in B4 below.
Also once we get past SP in column A4 the formula changes to reference the date created by using the value at the SP value.

So if we put the results in to column E the formula will change to =DATE(YEAR($E$6),MONTH($E$6),DAY($E$6))
The date also needs to be in the format text(xx,"mm/dd/yyyy")

Any suggestions on how to create this in Excel of VIA a VBA solution macro would be appreciated

Inputs
A1
=today()

A4 B4
ON1 Day
TN2 Day
SP2 Day
SN2 Day
1W7 Day
2W14 Day
3W21 Day
1M1 Month
2M2 Month
3M3 Month
4M4 Month
5M5 Month
6M6 Month
7M7 Month
8M8 Month
9M9 Month
10M10 Month
11M11 Month
1Y1 Year
15M15 Month
18M18 Month
21M21 Month
2Y2 Year
3Y3 Year
4Y4 Year
5Y5 Year
6Y6 Year
7Y7 Year
8Y8 Year
9Y9 Year
10Y10 Year
15Y15 Year
20Y20 Year
25Y25 Year
30Y30 Year

<colgroup><col span="2"></colgroup><tbody>
</tbody>
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
1. Make your table into three columns. Make column B the number to add, so column C contains Day Month or Year

2. In B1 put your code ON, TN, SP etc

3. In C1 =VLOOKUP(B1,A$4:C$1000,2,0)
In D1 =VLOOKUP(B1,A$4:C$1000,3,0)

4. In E1
=IF(D1="Day",A1+C1,IF(D1="Month",EDATE(A1,C1),(TEXT(A1,"dd/mm/")&(YEAR(A1)+C1))+0))
 
Last edited:
Upvote 0
I made a small example to parse the number and unit of measure from a cell and then to add to the input date appropriately... In my example, A4 has the value "30 Year"...

Getting Number Value (B4):

Code:
=LEFT(A4,SEARCH(" ",A4)-1)

Getting Unit Of Measure (C4):

Code:
=RIGHT(A4,LEN(A4)-SEARCH(" ",A4))

Adjusting Input Date (D4):

Code:
=IF(C4="Day",DATE(YEAR(A1),MONTH(A1),DAY(A1)+B4),IF(C4="Month",DATE(YEAR(A1),MONTH(A1)+B4,DAY(A1)),DATE(YEAR(A1)+B4,MONTH(A1),DAY(A1))))

f6AtIrA.png
 
Upvote 0
Hi - thanks for the response - I dont follow fully - where does your first formula go?

30/05/2018
ON1 Day=RIGHT(A4,LEN(A4)-SEARCH(" ",A4))=IF(C4="Day",DATE(YEAR(A1),MONTH(A1),DAY(A1)+B4),IF(C4="Month",DATE(YEAR(A1),MONTH(A1)+B4,DAY(A1)),DATE(YEAR(A1)+B4,MONTH(A1),DAY(A1))))
TN2 Day
SP2 Day
SN2 Day
1W7 Day
2W14 Day
3W21 Day
1M1 Month
2M2 Month
3M3 Month
4M4 Month
5M5 Month
6M6 Month
7M7 Month
8M8 Month
9M9 Month

<colgroup><col><col span="3"></colgroup><tbody>
</tbody>
 
Upvote 0
Hi - thanks for the response - I dont fully follow your proposed idea. My table needs to be split into three Column B number of days, months or years, column C is day, month or year? What goes into column A?
 
Upvote 0
Hi - thanks for the response - I dont fully follow your proposed idea. My table needs to be split into three Column B number of days, months or years, column C is day, month or year? What goes into column A?


Column A4 onwards contains ON (and other codes)
Column B4 onwards contains numbers (1,2, 2, 2, etc)
Column C4 onwards contains Day, Month, Year

The table is now split into three columns.
A1 contains your code (ON, SP etc)

In B1 put your code ON, TN, SP etc

In C1 =VLOOKUP(B1,A$4:C$1000,2,0)
In D1 =VLOOKUP(B1,A$4:C$1000,3,0)

In E1
=IF(D1="Day",A1+C1,IF(D1="Month",EDATE(A1,C1),(TEXT(A1,"dd/mm/")&(YEAR(A1)+C1))+0))
 
Upvote 0
Perfect that made it simpler to understand thanks for the reply. I know have my dates populated however I know have another parameter I need to include. I only want the date returned to be a weekday (Mon - Fri) so if it lands on a Sat or Sun, it will move forward to the next weekday i.e that Monday. Any ideas on that one? I am aware of the =weekday formula though including it in your formula has not worked however.
 
Upvote 0
I have tried this formula -
Code:
=IF(WEEKDAY(IF(C7="Day",DATE(YEAR($D$6),MONTH($D$6),DAY($D$6)+B7),IF(C7="Month",DATE(YEAR($D$6),MONTH($D$6)+B7,DAY($D$6)),DATE(YEAR($D$6)+B7,MONTH($D$6),DAY($D$6)))))=2,IF(C7="Day",DATE(YEAR($D$6),MONTH($D$6),DAY($D$6)+B7),IF(C7="Month",DATE(YEAR($D$6),MONTH($D$6)+B7,DAY($D$6)),DATE(YEAR($D$6)+B7,MONTH($D$6),DAY($D$6))))-3,IF(C7="Day",DATE(YEAR($D$6),MONTH($D$6),DAY($D$6)+B7),IF(C7="Month",DATE(YEAR($D$6),MONTH($D$6)+B7,DAY($D$6)),DATE(YEAR($D$6)+B7,MONTH($D$6),DAY($D$6))))-1)

This however subtracts 1 day from all my resultant dates which is not what I want - I want this to be only effective if the resultant date is a weekend day - Sat or Sun...
 
Upvote 0
Finally - further to this requirement if the resultant date falls on either Christmas day 25th Dec or New years Day 1st Jan and these are a weekday I need the resultant date to be the next business day. So if Xmas day is a Monday the date should go to the 26th however if Xmas day is a Friday the date should go to the 28th
 
Upvote 0

Forum statistics

Threads
1,215,205
Messages
6,123,632
Members
449,109
Latest member
Sebas8956

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