Formula for "contained in date range"

mick0005

Active Member
Joined
Feb 21, 2011
Messages
406
Hi all, here is what I am trying to do:

Please look at the image provided. I want to write a formula where in columns R through AA there is an output of "7" (days) that populates IF the dates in AB and AC are contained in that week.

So, for example in the first row of data, in week 10/25/11 for the dates of 7/3/11 through 12/31/11, I would need the cell to populate with a "7" since the week of 10/25 (10/25 -10/31) does fall within the 7/3/11 through 12/31/11 range. If it does NOT fall within the range, then I would want to know how many days were cut off in that week. For example, if the range of dates provided was 7/3/11 through 10/29/11 then the output would be "2" since it is cut off 2 days short of 10/31.

I am fairly certain this can all be done with a formula, I just can't get my head around the logic.

Hopefully this makes sense.

8-17-20113-54-31PM.jpg
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Is this what you wanted?
Excel Workbook
ABCDEFGHIJKLM
125/10/20111/11/20118/11/201115/11/201122/11/201129/11/20116/12/201113/12/201120/12/201127/12/2011
2
377/03/201131/12/2011
427/03/201129/10/2011
5
6
Sheet1
 
Upvote 0
Is this what you wanted?
Excel Workbook
ABCDEFGHIJKLM
125/10/20111/11/20118/11/201115/11/201122/11/201129/11/20116/12/201113/12/201120/12/201127/12/2011
2
377/03/201131/12/2011
427/03/201129/10/2011
5
6
Sheet1

That is EXACTLY what I need!!!! Oh my thank you so much. EXCEPT I am putting in the same formula (but changing for my cell locations) and getting the #REF error. Can you help?

I put this in as the formula:

=IF(AND($AB3(R$2+7)),7,6-(MAX(R$2,$AC3)-MAX(R$2,$AB3)))

What I did not show in my image was the the 10/25/11 week shown in my picture is in row 2, column R. (R2).. the week dates go across through AA2
 
Upvote 0
Here is the HTML add in code:

Excel Workbook
RSTUVWXYZAAABAC
1week startweek startweek startweek startweek startweek startweek startweek startweek startweek start
210/25/201111/1/201111/8/201111/15/201111/22/201111/29/201112/6/201112/13/201112/20/201112/27/2011
3#REF!7/3/201112/31/2011
4#REF!7/3/201110/29/2011
32oz Foam Data




That is EXACTLY what I need!!!! Oh my thank you so much. EXCEPT I am putting in the same formula (but changing for my cell locations) and getting the #REF error. Can you help?

I put this in as the formula:

=IF(AND($AB3(R$2+7)),7,6-(MAX(R$2,$AC3)-MAX(R$2,$AB3)))

What I did not show in my image was the the 10/25/11 week shown in my picture is in row 2, column R. (R2).. the week dates go across through AA2
 
Upvote 0
Sorry Mick,

I forgot that "<" and ">" symbols always give a problem :).

Here is the correct formula:
Excel Workbook
ABCDEFGHIJKLM
125/10/20111/11/20118/11/201115/11/201122/11/201129/11/20116/12/201113/12/201120/12/201127/12/2011
2
377/03/201131/12/2011
427/03/201129/10/2011
Sheet1


Asad
 
Upvote 0
And your formula should look like this
Code:
IF(AND($AB3 < R$2,$AC3 > (R$2+7)),7,6-(MAX(R$2,$AC3)-MAX(R$2,$AB3)))

Asad
 
Upvote 0
And your formula should look like this
Code:
IF(AND($AB3 < R$2,$AC3 > (R$2+7)),7,6-(MAX(R$2,$AC3)-MAX(R$2,$AB3)))
Asad

ASAD! You are the best. I wish you were local, I'd buy you a beer!

One more thing, if you have the time and initiative... the formula is currently outputting a negative number for dates that are BEYOND the start date of the week in AB3... is there an adjustment we can make to the formula that says if the result would be negative then output "0" instead?

Thanks again so much!
 
Upvote 0
ASAD! You are the best. I wish you were local, I'd buy you a beer!

One more thing, if you have the time and initiative... the formula is currently outputting a negative number for dates that are BEYOND the start date of the week in AB3... is there an adjustment we can make to the formula that says if the result would be negative then output "0" instead?

Thanks again so much!

Shoot - so now I am looking at it and wondering if I screwed up with explaining this. Let me explain what the spreadsheet does and maybe you can help.

The "week start" fields represent (in another spreadsheet) weeks of forecasts that my forecasting team puts together. The dates on the right hand side in AB and AC represent start and stop dates of individual markets that are "opting out" of getting a forecast during that time period (they don't need one because they are participating in a different program and getting a different forecast for that program). What I am hoping to do in the cells R3 to AA3 (and for the rest of the rows below them) is output the number of days that those individual markets (1 per row) will NEED a forecast in that given week. If the week in R2 is before or after the time frame indicated in AB, then we want a result of how many days in that week it needs a forecast for.

Does this make sense? I tested our current formula and it isn't giving me the right values. I don't know if it is a simple fix or not.
 
Upvote 0
Excel Workbook
RSTUVWXYZAAABAC
1week startweek startweek startweek startweek startweek startweek startweek startweek startweek start
210/25/201111/1/201111/8/201111/15/201111/22/201111/29/201112/6/201112/13/201112/20/201112/27/2011
377777777727/3/201112/31/2011
477777777727/3/201112/31/2011
577777777727/3/201112/31/2011
677777777727/3/201112/31/2011
7-116-116-116777777711/14/20113/15/2012
8-116-116-116777777711/14/20113/15/2012
32oz Foam Data




In this above example, since the markets are "opting out" from 7/3 to 12/31, they do not need a forecast for any week until the week of 12/27 in which they would need 2 days of forecast (the last two, 1/1 and 1/2). All other week's results should be 0.

For the week start of 11/14, they would need an output (require a forecast) of 6 days for week start 11/8 and 7 days for the 2 weeks prior.

I think I basically had you do the opposite of what I originally needed. Even I am confused at this point, so I hope you can help.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,506
Messages
6,179,158
Members
452,892
Latest member
yadavagiri

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