+ Reply to Thread
Results 1 to 9 of 9

Rounding to 6 minutes for company time sheet

Hybrid View

  1. #1
    Registered User
    Join Date
    11-28-2012
    Location
    VA
    MS-Off Ver
    Excel 2003
    Posts
    4

    Question Rounding to 6 minutes for company time sheet

    This is my company's increment system:

    Record time in increments of 6 minutes:
    0.1 = 6 minutes
    0.2 = 12 minutes
    0.3 = 18 minutes
    0.4 = 24 minutes
    0.5 = 30 minutes
    0.6 = 36 minutes
    0.7 = 42 minutes
    0.8 = 48 minutes
    0.9 = 54 minutes

    The current time sheet I'm using is this:
    12.02-12.15.xlsx

    The timesheet automatically rounds to the nearest quarter hour (15, 30, 45, 60). I need each punch in and out to round to the nearest 6 minutes reflecting my employers increments, as well as the total time being from 8.0 to 8.9 hours.

    Thanks so much!

  2. #2
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284

    Re: Rounding to 6 minutes for company time sheet

    Change the two 0.25s in the formula to 0.1

  3. #3
    Registered User
    Join Date
    11-28-2012
    Location
    VA
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: Rounding to 6 minutes for company time sheet

    Quote Originally Posted by Bob Phillips View Post
    Change the two 0.25s in the formula to 0.1
    How do I round the Log in and Log Out times?

  4. #4
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Rounding to 6 minutes for company time sheet

    If you want to round the Log in and out times within their own cells, you will need to use VBA. Alternately, you can have Excel round them internally while performing calculations on them.

    Also, your bio says you are using 2003 but this is at least a 2007 worksheet. Will this need to be 2003 compatable? Will it be saved as an xls file or an xlsm (workbooks containing vba cannot be xlsx files)
    ChemistB
    My 2?

    substitute commas with semi-colons if your region settings requires
    Don't forget to mark threads as "Solved" (Edit First post>Advanced>Change Prefix)
    If I helped, Don't forget to add to my reputation (click on the little star at bottom of this post)

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  5. #5
    Registered User
    Join Date
    11-28-2012
    Location
    VA
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: Rounding to 6 minutes for company time sheet

    Quote Originally Posted by ChemistB View Post
    If you want to round the Log in and out times within their own cells, you will need to use VBA. Alternately, you can have Excel round them internally while performing calculations on them.

    Also, your bio says you are using 2003 but this is at least a 2007 worksheet. Will this need to be 2003 compatable? Will it be saved as an xls file or an xlsm (workbooks containing vba cannot be xlsx files)
    It is 2007. Sorry. I have no idea what a VBA is. This is all like a foreign language to me

  6. #6
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Rounding to 6 minutes for company time sheet

    VBA is Excel's (actually MS Office's) programming language for macros and user defined functions. Basically a little code is written that is linked to those cells and it runs (if it is enabled) when something is entered into that cell. The key is that it has to be enabled. When you open a workbook that contains VBA, a little message pops up near the formula bar asking you if you want to "enable content". The user has to say yes to this to enable the content. Alternately, the folder that the sheet is stored in can be stored as a "trusted site" in each computer that will pull up that workbook and then it will automatically allow vba to be enabled. Let me look for Excel workarounds first.

  7. #7
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Rounding to 6 minutes for company time sheet

    Okay, as I mentioned, you could also do this during the calculation stage, rounding before subtracting, but keep the sign in/out times as is. However, this code will modify your times to the nearest 6 minutes. Then the calculations need to be modified,
    i.e. in F9, simplify that to
    =((E9-B9)-(D9-C9))*24

    An explaination. Excel uses the day as the unit of measurement with time and dates. So an hour = 1/24 = 0.041667, a minute = 1/(60*24) = 0.000694 and 6 minutes = 6/(60*24) = 0.0041667. In the code, I use the Excel Function MROUND which rounds to the nearest value as specified by the second argument in the function (I used 0.00417). Excel formats that as time.

    To enter your code into the workbook, Copy it,
    Right click on the sheet tab and "View code" (this will open the VBA editor)
    Paste the code into the large white text box on the right side of the VBA editor.
    I've attached your example, already modified.
    Private Sub Worksheet_Change(ByVal Target As Range)
    On Error Resume Next
    
    If Target.Count = 1 Then
        If Intersect(Target, Range("B9:E23")) Is Nothing Then Exit Sub
            Target = WorksheetFunction.MRound(Target.Value, 0.00417)
    End If
    
    End Sub
    Is that what you were looking for?
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    11-28-2012
    Location
    VA
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: Rounding to 6 minutes for company time sheet

    Quote Originally Posted by ChemistB View Post
    Okay, as I mentioned, you could also do this during the calculation stage, rounding before subtracting, but keep the sign in/out times as is. However, this code will modify your times to the nearest 6 minutes. Then the calculations need to be modified,
    i.e. in F9, simplify that to
    =((E9-B9)-(D9-C9))*24

    An explaination. Excel uses the day as the unit of measurement with time and dates. So an hour = 1/24 = 0.041667, a minute = 1/(60*24) = 0.000694 and 6 minutes = 6/(60*24) = 0.0041667. In the code, I use the Excel Function MROUND which rounds to the nearest value as specified by the second argument in the function (I used 0.00417). Excel formats that as time.

    To enter your code into the workbook, Copy it,
    Right click on the sheet tab and "View code" (this will open the VBA editor)
    Paste the code into the large white text box on the right side of the VBA editor.
    I've attached your example, already modified.
    Private Sub Worksheet_Change(ByVal Target As Range)
    On Error Resume Next
    
    If Target.Count = 1 Then
        If Intersect(Target, Range("B9:E23")) Is Nothing Then Exit Sub
            Target = WorksheetFunction.MRound(Target.Value, 0.00417)
    End If
    
    End Sub
    Is that what you were looking for?
    I just resaved the excel sheet you attached and saw the rounding for each punch in and out. For total time, it can only be 1 decimal so just reformat it, right?

  9. #9
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Rounding to 6 minutes for company time sheet

    right
    how's it working for you?

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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