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 Feb 16th, 2002, 04:55 PM   #1
Aladin Akyurek
MrExcel MVP
 
Aladin Akyurek's Avatar
 
Join Date: Feb 2002
Location: The Hague
Posts: 50,314
Default

Eons ago Hysen posted at the old board (see http://www.mrexcel.com/wwwboard/messages/7738.html ) the following question:

QUOTE
Posted by Hysen on December 01, 2001 at 04:15:56:

I have set up a Timesheet, which calculates the no. of total hrs worked between start time and end time. The work hours can go over midnight. E.g. start at 22:00 and end at 5:00 the next morning.

My question is: In addition to working out the total hrs worked, which I have done, I also need to calculate the number of hours & minutes (out of total hrs worked) that a employee works between 22:00 and 6:00. There are many scenarios, too many for using an ìifî statement. Egs are;

start@ end@ Hrs between 22:00 & 6:00 worked
18:00 2:00 4 hrs
23:00 7:00 7 hrs
14:00 22:30 30 mins.
Is there a formula I could use or do I have to resort to a macro.
Thanking in advance.

Hysen.

UNQUOTE

My initial approach was top-down, which I had to abandon very quickly. I published at least 2 early (insufficient) versions of the ongoing struggle as a response to similar questions at a news group. The final formula that eventually appears to resolve the problem is the result of countless bottom-up efforts (whence many IFs!). It seems appropriate that I post it at this board where all this has started:

=IF(OR(AND(A2 <= eCRIT,B2 >= sCRIT),AND(A2 <= eCRIT,B2 < eCRIT,B2-A2 < 0),A2 = B2),
MOD(eCRIT-A2,1)+MOD(B2-sCRIT,1),
IF(AND(OR(A2*24 < 12,NOT(B2-sCRIT > 0),B2*24 >= 12),NOT(AND(B2-A2 < 0,A2*24 > 12,A2 < sCRIT,B2 > eCRIT)),A2 < sCRIT,B2 > eCRIT,A2*24 <> 0,eCRIT < A2,B2 < sCRIT,NOT(AND(A2*24 < 12,B2*24 < 12,A2 >= eCRIT,B2-A2 < 0))),
0,
MOD(IF(B2 <= eCRIT,B2,IF(B2 >= sCRIT,B2,eCRIT))-IF(A2 <= eCRIT,A2,IF(A2 <= sCRIT,sCRIT,A2)),1)))


where sCRIT and eCRIT defines the interval for overtime (e.g., 22:00 and 6:00 respectively, as in Hysen's case). Many thanks to Hysen Struga and Jon Crash who helped me to finalize it.

If anyone wants to devise an alternative or to shorten the one above, I can send a test set to experiment with.

Special Note. Ian: I think the peculiar problem that you noted wrt MOD in computing time differences seems to be not a problem here.

PS. It's a hard job to post lengthy formulas!

Additional Note (added on: Sun, Feb 17, 02). The formula was crippled because of the existence of a number of the less than signs (a troubling problem at the old board which appears to be still with us). If interested in the formula, just drop me a line at

akyurek@xs4all.nl





[ This Message was edited by: Aladin Akyurek on 2002-02-16 16:01 ]

[ This Message was edited by: Aladin Akyurek on 2002-02-16 16:10 ]

[ This Message was edited by: Aladin Akyurek on 2002-02-17 07:23 ]
Aladin Akyurek is offline   Reply With Quote
Old Feb 16th, 2002, 05:11 PM   #2
keithkemble
Board Regular
 
Join Date: Feb 2002
Location: Leicestershire, U K
Posts: 157
Default

The secret with time is to get the formatting right.
I am not sure I understand you plight but in order to get the correct evaluationof elapsed time you need :
5 cols
a start time
b
keithkemble is offline   Reply With Quote
Old Feb 16th, 2002, 05:21 PM   #3
keithkemble
Board Regular
 
Join Date: Feb 2002
Location: Leicestershire, U K
Posts: 157
Default

The secret with time is to get the formatting right.
I am not sure I understand you plight but in order to get the correct evaluation of elapsed time you need :
5 columns
a start time Format (custom hh:mm)
b finish time Format (custom hh:mm)
c formula to establish diff in decimal form = (B1-A1)+If((A1>B1,1) format general
d conversion to 24hr formula = (B1-A1)+If(A1>B1,1) Format time 13:30
e diff in hours ( * 60 in minutes reqd)formula =If(c1=0,24,D1*24) format general

If you then hide cols c and d you can then summate all column e ( e being the shift total in hours or minutes).
This I think would simplify your analysys.
kk

keithkemble is offline   Reply With Quote
Old Feb 17th, 2002, 09:49 AM   #4
keithkemble
Board Regular
 
Join Date: Feb 2002
Location: Leicestershire, U K
Posts: 157
Default

Further to my previous answer you can change column f to this and this will return zero if there is no start and finish times.

If you change the cell F1 to
=IF(AND(A1=0,B1=0,TRUE),0,IF(C!=0,24,D1*24))
This will test for nil entry in both start and finish times

This is because in our business we work 365 days and you could have the same start and finish time which would mean a day has expired
Hope this helps
kk
keithkemble is offline   Reply With Quote
Old Feb 17th, 2002, 09:09 PM   #5
IML
MrExcel MVP
 
Join Date: Feb 2002
Location: Denver, CO
Posts: 1,744
Default

Bravo. I started playing with a "simplified" boolean formula, but quickly dismissed it when head just about exploded thinking of the different options. At the end of day, things would be greatly simplified if a true time and date were placed in this rather than "tricking" excel into beleiveing it was the next day.
IML is offline   Reply With Quote
Old Feb 18th, 2002, 12:03 AM   #6
Guest
 
Posts: n/a
Default

I have tried doing timecards with only cell formulas, the place had some flakey policies, such as allowing workers to clock in as soon as they walked in the door, even though the shift started an hour later, the forklift guy got a fifteen minute early start, the supervisor was paid from the moment he clocked in.............


You need to click Alt F11 and discover the Visual Basic Applications Editor.

When you are done, you will:

Have some (forms toolbox) buttons on the sheet.

Be well acquainted with "Cells(row,col).value" notations.

Become good with For loop = start to finish...Next control structures.

I tell you, I am embarrassed to admit how hard I beat the dead horse of cell formulas before I decided to tap Alt F11 and discover VBA

Good Luck!
  Reply With Quote
Old Feb 18th, 2002, 12:10 AM   #7
Aladin Akyurek
MrExcel MVP
 
Aladin Akyurek's Avatar
 
Join Date: Feb 2002
Location: The Hague
Posts: 50,314
Default

Quote:
On 2002-02-17 20:09, IML wrote:
Bravo. I started playing with a "simplified" boolean formula, but quickly dismissed it when head just about exploded thinking of the different options. At the end of day, things would be greatly simplified if a true time and date were placed in this rather than "tricking" excel into beleiveing it was the next day.
Ian: Maybe you're thinking of registering the date as well as the time when entering start and end times. This has come up at the Microsoft news group for worksheet functions, giving me the hope that I could drop further effort devising a single formula. But, alas. I don't know why that didn't work. Here is the thread where that has been proposed:

http://groups.google.com/groups?hl=e...4ax.com#link10

Another relevant thread is:

http://groups.google.com/groups?q=ca...=Google+Search

Both threads contain refs to the earlier versions of the formula I posted here.

Aladin
Aladin Akyurek 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 -4. The time now is 05:37 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
All contents Copyright 1998-2012 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