Results 1 to 5 of 5

Logic advice for max hours in week that overlaps month

Threaded View

  1. #1
    Registered User
    Join Date
    08-17-2014
    Location
    England
    MS-Off Ver
    Small Business Edition 2003
    Posts
    3

    Question Logic advice for max hours in week that overlaps month

    Hi all,

    I can't quite get my head around how to achieve something, hence looking for some logic advice and how people think it would work best in VBA.

    I have a scheduler which is simply Mon to Fri and number of hours each day that a task is worked on. So some might be 5 hours in a week and others could be 50 hours in a week. Every week I want to double the hours but to a maximum of 15, so the 5 week hour would get 5 additional hours and the 50 week hour would get additional 15. Make sense so far?

    My problem is that this has to be calculated monthly and when I calculate the following month it takes no account of the bonus hours that were allocated the previous month in the overlapping week. So where September and October overlap in a week my code at present could potentially allocate 15 bonus hours for the last two days of September and then again for the week when calculating October through the last three days. Make sense?

    Here is the code -
    dim myday as integer, mydate as date, maxdate as date, wrkdays(7) as string, bonus(5) as single
    dim mywk as integer, mymth as date, bhrs as single, thrs as single
    mymth = #9/1/2014#
    mydate = #9/1/2014#
    maxdate = #9/30/2014#
    wrkdays(1)=
    wrkdays(2)=10
    wrkdays(3)=5
    wrkdays(4)=
    wrkdays(5)=10
    wrkdays(6)=10
    wrkdays(7)=
    
    Do While mydate <= maxdate
    myday = Weekday(mydate)
        If myday > 1 And myday < 7 Then
                If wrkdays(myday) <> "" Then
                    mywk = DateDiff("ww", mymth, mydate, vbMonday)
                    bonus(mywk) = bonus(mywk) + wrkdays(myday)
                End If
        End If
        mydate = DateAdd("d", 1, mydate)
    Loop
    
    For mywk = 0 To 5
        bhrs = vbMin(bonus(x), 15)
        thrs = thrs + bhrs
    Next x
    
    'thrs then equals total bonus hours for the month
    vbmin is a simple function which returns the smaller of the two numbers being passed to it.

    So any ideas how I should reduce the first weeks bonus hours to compensate for any bonus hours claimed for that week in the previous month?

    Thanks in advance,

    Brad
    Last edited by bradsalmon; 08-17-2014 at 04:54 PM. Reason: code tags added

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 0
    Last Post: 08-14-2013, 11:21 AM
  2. [SOLVED] Showing Fridays of each month in a 4 week month and a five week month
    By david_j_p in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 05-09-2013, 06:27 AM
  3. Total hours and paid hours calculation advice
    By lozzauk in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 03-27-2013, 08:25 AM
  4. Replies: 0
    Last Post: 07-12-2012, 01:47 PM
  5. Replies: 10
    Last Post: 01-22-2012, 10:05 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