+ Reply to Thread
Results 1 to 4 of 4

VB Code to confirm and add Total hours worked.

Hybrid View

  1. #1
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    VB Code to confirm and add Total hours worked.

    Hello:

    Please refer to attached file.

    I have clockIn-Out info for employees as shown.
    I need a VB Code to update the # of numbers worked by employee after making adjusment in ClockIn-Out info.

    Currently the data is retrieved in excel as shown.
    Now after making changes in clockIn-Out info for employee, the corrected hours worked are as shown in
    Range AC1:AK20.

    I need to change data for all dates in cell for example: B3,B4,B9,B15,B16 and so on for 8/11/2014 so that it matches Range AC1:AK20.
    Same for other date.

    Let me know if you have any questions.
    Thanks.

    Riz
    Attached Files Attached Files

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: VB Code to confirm and add Total hours worked.

    Hi Riz,

    Try this:

    Sub RizCounter(): Dim CI As Date, CO As Date, ET As Date, r As Long, c As Long
    For c = 1 To Columns.Find("*", , , , xlByColumns, xlPrevious).Column Step 4
    For r = 2 To Columns(c).Find("*", , , , xlByRows, xlPrevious).Row
            If InStr(1, Cells(r, c), "Clock") Then
    CO = Cells(r, c + 2): CI = Cells(r, c + 1)
    CO = CDate(Trim(Replace(CStr(CO), "1/1/1904", "")))
    CI = CDate(Trim(Replace(CStr(CI), "1/1/1904", "")))
                ET = CO - CI
    Cells(r - 3, c + 1).Resize(2, 1).NumberFormat = "h:mm"
        Cells(r - 3, c + 1).Resize(2, 1).Value = ET
            End If: Next r: Next c
    End Sub
    Last edited by xladept; 09-28-2014 at 07:55 PM.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  3. #3
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    Re: VB Code to confirm and add Total hours worked.

    Hi xla:

    Works fine, except small tweaking.
    I need the hours worked as decimal, example 3:54 needs to be 3.90
    Please let me know if you have any questions.
    Thanks.

    Riz

  4. #4
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: VB Code to confirm and add Total hours worked.

    Hi Riz,

    Maybe:

    Sub RizCounter(): Dim CI As Date, CO As Date, ET As Date, r As Long, c As Long
    Dim ES As Single
    For c = 1 To Columns.Find("*", , , , xlByColumns, xlPrevious).Column Step 4
    For r = 2 To Columns(c).Find("*", , , , xlByRows, xlPrevious).Row
            If InStr(1, Cells(r, c), "Clock") Then
    CO = Cells(r, c + 2): CI = Cells(r, c + 1)
    CO = CDate(Trim(Replace(CStr(CO), "1/1/1904", "")))
    CI = CDate(Trim(Replace(CStr(CI), "1/1/1904", "")))
        ET = CO - CI: ES = Hour(ET) + Minute(ET) / 60
    Cells(r - 3, c + 1).Resize(2, 1).NumberFormat = "0.00"
        Cells(r - 3, c + 1).Resize(2, 1).Value = ES
            End If: Next r: Next c
    End Sub
    Last edited by xladept; 09-29-2014 at 02:56 PM. Reason: Type assignment

+ 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. Code for looking in Column A find employee ID and pull total hours worked
    By prdponce in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 09-27-2013, 04:37 PM
  2. Replies: 4
    Last Post: 02-12-2013, 07:01 AM
  3. Replies: 2
    Last Post: 02-11-2013, 02:26 PM
  4. Replies: 6
    Last Post: 05-03-2010, 12:03 PM
  5. total of hours worked
    By carolynkeene in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 12-21-2006, 03:29 PM

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