MrExcel Message Board


Go Back   MrExcel Message Board > Question Forums > Excel Questions

Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only.

Reply
 
Thread Tools Display Modes
Old Jan 6th, 2009, 02:08 AM   #1
mgirvin
 
Join Date: Dec 2005
Location: Seattle, WA
Posts: 321
Default Count Number Of Days Except Sunday

Dear Smartest Excel People In The World,

In B13 I have the start date: 12/1/2008
In C13 I have the end date: 1/5/2009
In cell D13 I want a formula that counts the number of days between the two dates that are not Sunday. The start and end dates are included in the count.

I have created this formula using Ctrl + Shift + Enter:

{=SUM(IF(WEEKDAY(ROW(INDIRECT(B13&":"&C13)),2)<>7,1,0))}

I have also created this formula using Ctrl + Shift + Enter:

{=SUM(IF(TEXT(ROW(INDIRECT(B13&":"&C13)),"ddd")<>"Sun",1,0))}

They both seem to work. I get a result of 31.

Is there a formula that is better than this, more efficient than this, or "less expensive"?
__________________
Sincerely, Mike Gel Girvin
mgirvin is offline   Reply With Quote
Old Jan 6th, 2009, 02:25 AM   #2
shemayisroel
 
shemayisroel's Avatar
 
Join Date: Sep 2008
Location: Sydney - Australia
Posts: 1,426
Default Re: Count Number Of Days Except Sunday

Heres another way

=SUMPRODUCT(--(WEEKDAY(ROW(INDIRECT(B13&":"&C13)),2)<7))
__________________
enercheenhologoskaihoogosenprostontheonkaitheosenhologosnarchhnoogovkailogohnprvtonqeonkaiqeovhnologov
shemayisroel is offline   Reply With Quote
Old Jan 6th, 2009, 02:27 AM   #3
shemayisroel
 
shemayisroel's Avatar
 
Join Date: Sep 2008
Location: Sydney - Australia
Posts: 1,426
Default Re: Count Number Of Days Except Sunday

Or you could use the below but you will need to ensure you tick the add in 'Analysis Toolpack' through the tools menu option.

=NETWORKDAYS(B13,C13)+SUMPRODUCT(--(WEEKDAY(ROW(INDIRECT(B13&":"&C13)))=7))
__________________
enercheenhologoskaihoogosenprostontheonkaitheosenhologosnarchhnoogovkailogohnprvtonqeonkaiqeovhnologov
shemayisroel is offline   Reply With Quote
Old Jan 6th, 2009, 03:18 AM   #4
Fazza
MrExcel MVP
 
Join Date: May 2006
Location: Australia
Posts: 4,960
Default Re: Count Number Of Days Except Sunday

Without an array formula, I don't know about the speed ...
Code:
=C13-B13+(CEILING(C13,7)>CEILING(B13,7))-(CEILING(C13,7)-CEILING(B13,7))/7
Fazza is offline   Reply With Quote
Old Jan 6th, 2009, 06:11 AM   #5
mgirvin
 
Join Date: Dec 2005
Location: Seattle, WA
Posts: 321
Default Re: Count Number Of Days Except Sunday

Dear shemayisroel,

Thank you very much for your amazing formulas!

I like the formula:

=SUMPRODUCT(--(WEEKDAY(ROW(INDIRECT(B13&":"&C13)),2)<7))

What are the advantages to your formula over this one:

{=SUM(IF(WEEKDAY(ROW(INDIRECT(B13&":"&C13)),2)<>7,1,0))}


Also, If I use this formula:

=SUMPRODUCT((WEEKDAY(ROW(INDIRECT(B13&":"&C13)),2)<7)*1)

Instead of this one:

=SUMPRODUCT(--(WEEKDAY(ROW(INDIRECT(B13&":"&C13)),2)<7))

Is there an advantage to the double negative over the multiply by 1? I have actually been wondering about this for a while. I tend to use Multiply by 1 most of the time, but often I see the double negative at this Message Board.

Thanks!
__________________
Sincerely, Mike Gel Girvin
mgirvin is offline   Reply With Quote
Old Jan 6th, 2009, 06:14 AM   #6
mgirvin
 
Join Date: Dec 2005
Location: Seattle, WA
Posts: 321
Default Re: Count Number Of Days Except Sunday

Dear Fazza,

Wow! That is an incredible non-array formula:

=C13-B13+(CEILING(C13,7)>CEILING(B13,7))-(CEILING(C13,7)-CEILING(B13,7))/7

I have run through formula evaluator a few times and am starting to get it (not really). Can you explain the logic of how it gets the right number?

Thanks!
__________________
Sincerely, Mike Gel Girvin
mgirvin is offline   Reply With Quote
Old Jan 6th, 2009, 06:19 AM   #7
shemayisroel
 
shemayisroel's Avatar
 
Join Date: Sep 2008
Location: Sydney - Australia
Posts: 1,426
Default Re: Count Number Of Days Except Sunday

Quote:
Originally Posted by mgirvin View Post
Dear shemayisroel,

Thank you very much for your amazing formulas!

I like the formula:

=SUMPRODUCT(--(WEEKDAY(ROW(INDIRECT(B13&":"&C13)),2)<7))

What are the advantages to your formula over this one:

{=SUM(IF(WEEKDAY(ROW(INDIRECT(B13&":"&C13)),2)<>7,1,0))}


Also, If I use this formula:

=SUMPRODUCT((WEEKDAY(ROW(INDIRECT(B13&":"&C13)),2)<7)*1)

Instead of this one:

=SUMPRODUCT(--(WEEKDAY(ROW(INDIRECT(B13&":"&C13)),2)<7))

Is there an advantage to the double negative over the multiply by 1? I have actually been wondering about this for a while. I tend to use Multiply by 1 most of the time, but often I see the double negative at this Message Board.

Thanks!
mgirvin your welcome,

Not sure about the advantages perhaps one of the MVP's can help as all I know is it works and yields the required result

Regarding your SUMPRODUCT query, check out the below link as there is some discussion around what you are looking for...

Hope this helps

http://www.xldynamic.com/source/xld.SUMPRODUCT.html
__________________
enercheenhologoskaihoogosenprostontheonkaitheosenhologosnarchhnoogovkailogohnprvtonqeonkaiqeovhnologov
shemayisroel is offline   Reply With Quote
Old Jan 6th, 2009, 07:06 AM   #8
Fazza
MrExcel MVP
 
Join Date: May 2006
Location: Australia
Posts: 4,960
Default Re: Count Number Of Days Except Sunday

Quote:
Originally Posted by mgirvin View Post
=C13-B13+(CEILING(C13,7)>CEILING(B13,7))-(CEILING(C13,7)-CEILING(B13,7))/7

...

Can you explain the logic of how it gets the right number?
Sure, Mike.

C13-B13 is just the days from start to end - so it includes Sundays.

Ceiling(C13,7) is one Sunday, and Ceiling(B13,7) another.
so for Dec 1st '08 and Jan 5th '09 these are Dec 6th '08 and Jan 10th '09

the (ceiling(c13,7)>ceiling(b13,7)) adds one if the dates are in different weeks. If both b13 & c13 are the same, then this would not add 1.

and the last term takes the difference in those Sunday dates and divides by 7. so the number of Sundays is subtracted.

Maybe easiest seen by loading a few dates and seeing the results.

Do you plan, Mike, to evaluate which formula is fastest? It would be interesting to know.

Cheers, Fazza
Fazza is offline   Reply With Quote
Old Jan 6th, 2009, 02:59 PM   #9
barry houdini
MrExcel MVP
 
Join Date: Mar 2005
Location: England
Posts: 14,295
Default Re: Count Number Of Days Except Sunday

Quote:
Originally Posted by Fazza View Post
Without an array formula, I don't know about the speed ...
Code:
=C13-B13+(CEILING(C13,7)>CEILING(B13,7))-(CEILING(C13,7)-CEILING(B13,7))/7
I don't think it gives the right results in all circumstances. If B13 is today (Tuesday 6th January 2009) and C13 is tomorrow I get a result of 1, shouldn't that be 2?

Try

=C13-B13-INT((1+C13-B13-WEEKDAY(C13))/7)
barry houdini is online now   Reply With Quote
Old Jan 6th, 2009, 08:38 PM   #10
mgirvin
 
Join Date: Dec 2005
Location: Seattle, WA
Posts: 321
Default Re: Count Number Of Days Except Sunday

Dear Fazza,

Thanks for the explanation! It really helps.
__________________
Sincerely, Mike Gel Girvin
mgirvin is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT +1. The time now is 03:04 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
All contents Copyright 1998-2009 by MrExcel Consulting.
diabetic desserts recipes recipes Diabetic Soups Holiday Pizza Recipes Popcorn Recipes Recipes For Microwave Pasta Recipes Casserole Recipes Chili Recipes Curry Recipes Crockpot Recipes Apples Recipes Bread Recipes Vegetarian Recipes Vegetable recipes Desserts Recipes Appetizers Ethnic Recipes Meat Dishes Barbecue Recipes Sauces Recipes Marinade Recipes Low Fat Recipes Frugal Gourmet Kitchen Classics Recipes On The Grill Cook Books Seafood Recipes Cajun Recipes Breads Low Fat Low Fat Breads Bread Machine Recipes Yeast Breads Quick Breads Fat Free Vegetarian Salad Recipes Eggplant Recipes Radish Recipes Tomato Recipes Jalapeno Recipes Potato Recipes Lettuce Recipes Cabbage Recipes Beans Ambrosia Recipes Biscotti Recipes Desserts Low Fat Cookie Recipes Cheesecake Recipes Cake Recipes Pie Recipes Muffin Recipes Custard Recipes Best Appetizers Appetizers Low Fat Salsa Recipes Dip Recipes International Recipes Afghan Recipes Alaska Recipes French Recipes German Recipes Greek Recipes Italian Recipes Spanish Recipes Thai Recipes Korean Recipes Chinese Recipes Mexican Recipes Indian Recipes Beef Recipes Pork Pork & Ham Pork Butts Pork Chop Recipes Pork Ribs Rulled Pork Poultry Recipes Stews Recipes Ground Beef Barbecue Grill Barbecue Smoker All Purpose Sauce BBQ Sauce Barbecue Sauce Carolina BBQ Sauce Pickle Recipes Marinades Smoking Low Fat Appetizers & Dips Low Fat Breakfast Low Fat Cakes Low Fat Cheesecakes Low Fat Cookies Low Fat Desserts Low Fat Fish & Seafood Low Fat Meats Low Fat Pasta Low Fat Pies Low Fat Salads Low Fat Sandwiches Low Fat Sauces & Condiments Low Fat Sides Low Fat Soups Low Fat Vegetarian Baker's Dozen Taste of Home Recipe Book Bon Appetit Cookbook Blacktie Cookbook Buster Cook Book Cookbook USA Cook Book Cook Book Sara's Cookbook Sara's Cookbook Appetizers and Dips Poultry recipes Diabetic recipes Holiday recipes Miscellaneous recipes 110 recipes 1986 Usenet cookbook 2900 recipes Cyberrealm recipes Great sysops of world Specialty recipes Ceideburg recipes Cheese recipes Chili recipes Fruits recipes Garlic recipes Great chefs of NY Londontowne recipes Raisins recipes Recipes for kids US Food Vegetarian recipes Bread recipes Drinks Meat Dishes Brisket recipes Caribou recipes Chicken recipes Filet mignons recipes Pork recipes Swordfish recipes Turkey recipes Pasta recipes Uncategorized recipes Ethnic recipes Canada recipes English recipes Ethiopia recipes Germany recipes Greece recipes Mexican recipes Philippines recipes Welsh recipes Microwave recipes Soups recipes Vegetable recipes Asparagus recipes Barley recipes Brown rice recipes Lentil recipes Mushrooms recipes Salads recipes Wild rice Desserts recipes Cakes recipes Chocolate recipes Cookies recipes Ice cream recipes