Need some help with formulas and VBA involving time and date

eyanosa

New Member
Joined
Dec 11, 2014
Messages
6
First off, my project is a weekly sleep log I am creating. Cell A2 contains the Start Date of the log. Range C4-P4 contain the time one went to bed. Range C5-P5 contain the time when one woke up. Each of these ranges are double cell merged, which is why there are so many cells for a weekly log, and both of the time ranges are formatted as time.


What I am looking for here is this;



  • My date field needs to auto-update every week. It should only replace itself, if it has been a week or more since the currently inputted date.
  • I also need to figure out how to calculate the amount of time one is awake for. So far, I am using the below code. This does indeed work, provided there is a time entered within E4; however, if someone did not go to sleep for an entire day, then the calculation is messed up because we have empty cells. I am including a screenshot to help with the explanation.
Code:
=IFERROR(TEXT(IF(C5>E4,E4+1-C5,E4-C5),"h") & " hours and "  & MINUTE(IF(C5>E4,E4+1-C5,E4-C5)) & " minutes.", "0 hours and  0 minutes.")





I've done a lot of searching trying to figure this out on my own, and after 6 days, I think it is time to ask for help. So, with that in mind, any and all help in this would be very much appreciated.
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.

Forum statistics

Threads
1,203,052
Messages
6,053,234
Members
444,648
Latest member
sinkuan85

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