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 .
Last edited by vamshi57; 12-12-2009 at 02:15 PM.
We would need to know what the employee is logging into and off of. Also, what is producing the dump? Where is the code?
Why not just push the data into a Pivot ?
This will give you per employee one record per day with their respective IN/OUT timesRow 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
(above assumes shifts don't cross midnight)
My Recommended Reading:
Volatility
Sumproduct & Arrays
Pivot Intro
Email from XL - VBA & Outlook VBA
Function Dictionary & Function Translations
Dynamic Named Ranges
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 theicon 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!)
Awesome ... Macro is too good .. It exactly gave me the results I needed . Thanks much
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 theicon 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!)
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 .
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 theicon 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!)
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks