Add a 1 in a cell based on a date range

abrig005

Board Regular
Joined
Jan 6, 2017
Messages
82
Office Version
  1. 365
Platform
  1. Windows
Hello,
I am trying to figure out the formula for the following: Starting in G2 I want to add a 1 when the dates in C2 and D2 are within the range of G1 and continue on for each cell down and across. The formula I have now does that. However, I cant figure out how to make a formula where:

Add a 1 if the date in C2 (TO) starts on the 1st to the 14th and do not add a 1 if the date in C2 starts on the 15th or later.

Do not add a 1 if the date in D1 (FROM) is 1st through the 14th and add a 1 if the date is on the 15th or later.

thank you!

vhuvrc.png
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Hi,

Not absolutely clear on what you're asking, are those 2 separate conditions for 2 separate formulas, or combined, the following is based on your description combined.


Book1
CDEFGHI
118-Jan18-Feb18-Mar
21/1/20183/30/2018111
31/15/20183/30/2018
41/1/20183/15/201811
Sheet67
Cell Formulas
RangeFormula
G2=IF(AND(G$1>=$C2,DAY($C2)<15,G$1<=$D2,DAY($D2)>14),1,"")
 
Upvote 0
Thanks for the help!
I did't explain it thoroughly.

if c begins between 1/1/2018 - 1/14/2018 cell g would get a 1
if d ends between 3/15/2018 - 3/31/2019 cells h and i get a 1 (like you have it)

if cell c begins between 1/15/2018 - 1/31/2018 cell g would not get a 1
if cell d ends between 3/1/2018 - 3/14/2018 only cell H would get a 1 but not I

if cell c = 1/1/2018 and D = 3/15/2018 G, H, I would all have ones

hopefully that explains it better and thank you again!
 
Upvote 0
Ok, took some time and thinking trying to understand your requirement, I believe this will do what you ask.

I can't test for all your possible data, since you just posted a picture and Not something we can copy into Excel, and I don't want to replicate your data manually, so test this out and see if it works for you:


Book1
CDEFGHI
118-Jan18-Feb18-Mar
21/10/20183/25/2018111
31/15/20183/14/20181
41/1/20183/15/2018111
Sheet67
Cell Formulas
RangeFormula
G2=IF(OR(AND(MONTH($C2)=MONTH(G$1),DAY($C2)<15),AND(MONTH(G$1)>MONTH($C2),MONTH(G$1)$D2)),AND(MONTH($D2)=MONTH(G$1),DAY($D2)>14)),1,"")


G2 formula copied down and across as far as needed.
 
Last edited:
Upvote 0
I will test it today. I can't thank you enough for taking the time to figure this out for me!!!!!!!!!!!!!!!!!!!
Have a great day!
 
Upvote 0
Had another look today at your sample, my formula in Post #4 did Not account for the Year, and also in case you have FROM and TO dates that crosses over years (i.e. 2017 to 2019, 2017 to 2020, etc.), Test this Updated formula:

SIDENOTE: your TO and FROM Column Headers seems Backwards?


Book1
CDEFGHI
118-Jan18-Feb1-Mar
21/10/20183/25/2018111
31/10/20193/25/2019
41/10/20173/25/2019111
51/15/20183/14/20181
61/1/20183/15/2018111
Sheet67
Cell Formulas
RangeFormula
G2=IF(OR(AND(MONTH($C2)=MONTH(G$1),IF(YEAR(G$1)=YEAR($C2),DAY($C2)<15,IF(AND(YEAR(G$1)>YEAR($C2),YEAR(G$1)<=YEAR($D2)),1,0))),AND(MONTH(G$1)>MONTH($C2),MONTH(G$1)$D2),YEAR($C2)<=YEAR(G$1),YEAR($D2)>=YEAR(G$1)),AND(MONTH($D2)=MONTH(G$1),IF(YEAR(G$1)=YEAR($D2),DAY($D2)>14,IF(AND(YEAR(G$1)>=YEAR($C2),YEAR(G$1)$D2)),1,0)))),1,"")


Formula copied down and across as far as needed.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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