+ Reply to Thread
Results 1 to 2 of 2

Employee schedule - Calculate total hours from time in 1 cell; auto format time

  1. #1
    Registered User
    Join Date
    05-30-2017
    Location
    USA
    MS-Off Ver
    Office for Mac
    Posts
    1

    Employee schedule - Calculate total hours from time in 1 cell; auto format time

    I have an existing employee schedule excel file to which I'd like to make "smarter."

    For each employee, time is entered in one cell (e.g. 7AM-3PM) for each day of the week. I would like to have the Total Hours for each employee calculated at the end of the week. I have a formula that does that, but it brings up additional problems. It's not allowing me to copy the formula here but I have attached the sheet with the formula in cell I4 to give an idea.

    In this formula, the time needs to be entered in the format "XX:XX AM - XX:XX PM" otherwise it doesn't work. Also if a cell is blank or says OFF, it again doesn't work. So what I would like is to automatically convert times entered in any cell as "7AM-3PM" to the format "7:00 AM - 3:00 PM."

    Also, if a cell value is blank or says OFF, for it to consider the value of the cell to be "00:00 AM - 00:00 AM" but still be displayed as blank/OFF.

    The way I am calculating the total hours for the week is summing up the formula above for each day (it becomes very long and I'm not sure if this is the best way to do it).

    Any help for this would be appreciated.

    Thanks
    Attached Files Attached Files

  2. #2
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Employee schedule - Calculate total hours from time in 1 cell; auto format time

    I am normally a fan of getting "regular" Excel to do as much of the heavy lifting as possible and use VBA only to sew and bolt the pieces together. However, there are some times when the formulas get long and hairy and a UDF is a lot cleaner (in this case because we can loop through the range of days rather than add them up as separate formulas).

    The logic is fairly simple:
    - Loop through the days in the selected range
    - If a cell has a dash in the data, deal with it, otherwise ignore it.
    - Separate it into start and end time strings
    - Add a space before the AM or PM
    - Apply TimeValue to the resulting strings to get real times
    - Subtract the times
    - Keep a running total.
    Attached Files Attached Files
    One spreadsheet to rule them all. One spreadsheet to find them. One spreadsheet to bring them all and at corporate, bind them.

    A picture is worth a thousand words, but a sample spreadsheet is more likely to be worked on.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. How to calculate total hours in a cell: Time A and P
    By AussieSF in forum Excel General
    Replies: 23
    Last Post: 04-11-2016, 06:25 AM
  2. Creating an employee work schedule that will calculate time worked
    By Tlyke212 in forum Excel - New Users/Basics
    Replies: 4
    Last Post: 12-28-2015, 12:56 AM
  3. Replies: 0
    Last Post: 03-02-2015, 07:59 AM
  4. [SOLVED] Using Macros to calculate employee hours on a schedule
    By christhweatt in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-20-2013, 05:21 AM
  5. making a schedule with auto time format and adding total hours
    By damagedbodies in forum Excel General
    Replies: 0
    Last Post: 04-30-2012, 02:04 PM
  6. calculate of total working time of an employee
    By kanwal_deep in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 05-19-2007, 05:58 AM
  7. Replies: 2
    Last Post: 01-06-2005, 02:06 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1