Results 1 to 11 of 11

Calculating the time elapsed between two times when there is lunch and two breaks included

Threaded View

decubal Calculating the time elapsed... 03-20-2014, 03:37 AM
Kaper Re: Calculating the time... 03-20-2014, 06:49 PM
kvsrinivasamurthy Re: Calculating the time... 03-21-2014, 05:47 AM
Kaper Re: Calculating the time... 03-21-2014, 07:23 AM
decubal Re: Calculating the time... 03-25-2014, 02:59 AM
decubal Re: Calculating the time... 03-25-2014, 07:38 AM
Kaper Re: Calculating the time... 03-27-2014, 06:02 AM
decubal Re: Calculating the time... 03-28-2014, 06:25 AM
Kaper Re: Calculating the time... 03-29-2014, 03:41 AM
decubal Re: Calculating the time... 03-31-2014, 01:08 PM
Kaper Re: Calculating the time... 03-31-2014, 01:18 PM
  1. #2
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,863

    Re: Calculating the time elapsed between two times when there is lunch and two breaks incl

    I started working on formula (as the subforum heading suggests, but it quickly started to grow. So gave up and prepared short UDF - a small macro which can be used the same way as build-in functions. The only difference is that macros have to be enabled in excel.

    Have a look on attached file and code below. I tried to use self explanatory variable names.

    calling function can be seen in the spreadsheet - first argument is relative address of the registered time, and two other are ranges with absolute addresses of work start-end and breaks (you are no longer limited to 3 ;-) ).

    Function takt(r_end As Range, r_time As Range, r_breaks As Range) As Variant
    Dim i As Integer, t_start As Double, t_end As Double, t_break As Double, breaks
    Application.Volatile
    If r_end.Cells.Count = 1 And r_time.Cells.Count = 2 And r_breaks.Columns.Count = 2 Then
      t_start = IIf(r_end.Offset(0, -1) <> r_end.Offset(-1, -1), r_time(1), r_end.Offset(-1, 0))
      t_end = WorksheetFunction.Min(r_end, r_time(2))
      breaks = r_breaks.Value
      For i = 1 To UBound(breaks) 'correction of start/end
        breaks(i, 2) = breaks(i, 2) / (24 * 60) + breaks(i, 1)
        If t_start >= breaks(i, 1) And t_start <= breaks(i, 2) Then t_start = breaks(i, 2)
        If t_end >= breaks(i, 1) And t_end <= breaks(i, 2) Then t_end = breaks(i, 2)
      Next i
      For i = 1 To UBound(breaks) 'whole breaks inside
        If t_start <= breaks(i, 1) And t_end >= breaks(i, 2) Then t_break = t_break + breaks(i, 2) - breaks(i, 1)
      Next i
      takt = (t_end - t_start - t_break) * 24 * 60
    Else
      takt = "bad data"
    End If
    End Function
    Attached Files Attached Files
    Best Regards,

    Kaper

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Excel 2007 : Calculating all lunch breaks in Timesheet
    By italiansun in forum Excel General
    Replies: 0
    Last Post: 11-02-2011, 05:37 PM
  2. Subtracting lunch breaks from different shift times
    By badger in forum Excel General
    Replies: 6
    Last Post: 08-31-2011, 12:45 PM
  3. Calculating time, potential lunch break
    By B1123 in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 10-13-2008, 09:18 AM
  4. Replies: 2
    Last Post: 08-07-2008, 05:22 AM
  5. calculate elapsed time between dates and times
    By Jenna in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 01-25-2006, 12:45 PM

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