+ Reply to Thread
Results 1 to 8 of 8
  1. #1
    Registered User
    Join Date
    11-07-2009
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    74

    Login - Logout report

    Attached is the login-logout report for my team . Which gives me employee login time & logoff time . The dump has few entries which are repeated . For ex : In Cell D5 employee logged in , E5 has a logout time ( which is incorrect ) , while cell D6 has a login time ( which is incorrect ) , E6 has a logout time which is correct . So for 4th Dec I wanted to have D5 ( for login ) - E6 ( for logout ) . In the same way , I have many cells which has been repeated .


    Hint - (1) Days shouldn't not be repeated . (2) Logout time shuld be greater than the login time for that day ( & rest should be eliminated for that day )


    I'm not sure if I have explained it clearly or not. Do let me know if I can provide any other information .
    Attached Files Attached Files
    Last edited by vamshi57; 12-12-2009 at 02:15 PM.

  2. #2
    Forum Contributor
    Join Date
    12-02-2009
    Location
    Akron, Ohio
    MS-Off Ver
    Excel 2007
    Posts
    182

    Re: Login - Logout report

    We would need to know what the employee is logging into and off of. Also, what is producing the dump? Where is the code?

  3. #3
    Forum Moderator DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Suffolk, UK
    MS-Off Ver
    2002, 2007 & 2010
    Posts
    21,379

    Re: Login - Logout report

    Why not just push the data into a Pivot ?

    Row Fields:
    -- Name
    -- Date

    Data Fields:
    -- Login Time set to MIN
    -- Logout Time set to MAX
    set number format of the above to h:mm:ss
    This will give you per employee one record per day with their respective IN/OUT times
    (above assumes shifts don't cross midnight)

  4. #4
    Forum Guru JBeaucaire's Avatar
    Join Date
    03-21-2008
    Location
    Bakersfield, CA
    MS-Off Ver
    2010
    Posts
    18,225

    Re: Login - Logout report

    This should take care of it for you:
    Code:
    Option Explicit
    
    Sub LogInOutMerge()
    'JBeaucaire  (12/11/2009)
    Dim LR As Long, i As Long
    Application.ScreenUpdating = False
    
    LR = Range("A" & Rows.Count).End(xlUp).Row
    
    Columns("A:E").Sort Key1:=Range("A2"), Order1:=xlAscending, Key2:=Range("B2"), _
        Order2:=xlAscending, Key3:=Range("D2"), Order3:=xlAscending, Header:=xlYes, _
        OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
        DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, DataOption3:=xlSortNormal
    
    For i = LR To 3 Step -1
        If Cells(i, "B") = Cells(i - 1, "B") And Cells(i, "C") = Cells(i - 1, "C") Then
            If Cells(i, "E") > Cells(i - 1, "E") Then
                Cells(i - 1, "E") = Cells(i, "E")
                Rows(i).Delete xlShiftUp
            End If
        End If
    Next i
    
    Application.ScreenUpdating = True
    End Sub
    ===========
    How/Where to install the macro:

    1. Open up your workbook
    2. Get into VB Editor (Press Alt+F11)
    3. Insert a new module (Insert > Module)
    4. Copy and Paste in your code (given above)
    5. Get out of VBA (Press Alt+Q)
    6. Save your sheet

    The macro is installed and ready to use. Press Alt-F8 and select LogInOutMerge from the macro list.

    Try this on a copy of your data.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    “None of us is as good as all of us” - Ray Kroc
    “Actually, I *am* a rocket scientist.” - JB (little ones count!)

  5. #5
    Registered User
    Join Date
    11-07-2009
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    74

    Re: Login - Logout report

    Awesome ... Macro is too good .. It exactly gave me the results I needed . Thanks much

  6. #6
    Forum Guru JBeaucaire's Avatar
    Join Date
    03-21-2008
    Location
    Bakersfield, CA
    MS-Off Ver
    2010
    Posts
    18,225

    Re: Login - Logout report

    If that takes care of your need, be sure to EDIT your original post, click Go Advanced and mark the PREFIX box [SOLVED].


    (Also, use the blue "scales" icon in our posts to leave Reputation Feedback, it is appreciated)
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    “None of us is as good as all of us” - Ray Kroc
    “Actually, I *am* a rocket scientist.” - JB (little ones count!)

  7. #7
    Registered User
    Join Date
    11-07-2009
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    74

    Re: Login - Logout report

    I previous sheet I have attached is modified by me to make my explanation easier . Can you modify the macro to adjust the below format . Infact I get the dump in the attached format .

    Quick question - Is there any way this can be done by formulaes or through pivots ,,,, just in case . as it would be easier - irrespective of what format I have the data in . If not no issues , I'm still okay with macro .
    Attached Files Attached Files

  8. #8
    Forum Guru JBeaucaire's Avatar
    Join Date
    03-21-2008
    Location
    Bakersfield, CA
    MS-Off Ver
    2010
    Posts
    18,225

    Re: Login - Logout report

    This will work on the shown layout, and it will adjust the columns to display the times for you:
    Code:
    Option Explicit
    
    Sub LogInOutMerge()
    'JBeaucaire  (12/11/2009)
    Dim LR As Long, i As Long
    Application.ScreenUpdating = False
    
    LR = Range("A" & Rows.Count).End(xlUp).Row
    
    Columns("C:C").TextToColumns Destination:=Range("C1"), DataType:=xlDelimited, _
        TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
        Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
        :=Array(1, 3), TrailingMinusNumbers:=True
    Columns("D:D").TextToColumns Destination:=Range("D1"), DataType:=xlDelimited, _
        TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
        Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
        :=Array(1, 3), TrailingMinusNumbers:=True
        
    Columns("C:D").NumberFormat = "[$-409]h:mm:ss AM/PM;@"
    Columns("C:D").AutoFit
    
    Columns("A:E").Sort Key1:=Range("A2"), Order1:=xlAscending, Key2:=Range("B2"), _
        Order2:=xlAscending, Key3:=Range("C2"), Order3:=xlAscending, Header:=xlYes, _
        OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
        DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, DataOption3:=xlSortNormal
    
        For i = LR To 3 Step -1
            If Cells(i, "B") = Cells(i - 1, "B") And Cells(i, "E") = Cells(i - 1, "E") Then
                If Cells(i, "D") > Cells(i - 1, "D") Then
                    Cells(i - 1, "D") = Cells(i, "D")
                    Rows(i).Delete xlShiftUp
                End If
            End If
        Next i
    
    Application.ScreenUpdating = True
    End Sub
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    “None of us is as good as all of us” - Ray Kroc
    “Actually, I *am* a rocket scientist.” - JB (little ones count!)

Thread Information

Users Browsing this Thread

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

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.2.0