Fixing Excel timesheet by time in and time out per user and date











up vote
0
down vote

favorite












I have this:



badly formatted table



which is difficult to read, 'I' means time in and 'O' means time out.



I want to transform it like this:



this



I want to align each time in and time out to its respective employee ID and date. Thanks



EDIT



I's and O's in the first table aren't necessarily alternating, there may be 3 I's before its respective O show up.



The result should be:
1. missing values of time in and out should show as blank
2. editable so the user can fill out missing time ins or outs and;
3. the t










share|improve this question
























  • Possible duplicate of How to combine values from multiple rows into a single row in Excel?
    – Scott
    Nov 19 at 3:27










  • Create a pivot, use employee number and date as the rows, and min and max of time for time as the values for time in and time
    – PeterH
    Nov 19 at 14:33










  • can there be multiple ins on the same date? Conversely multiple outs on the same date?
    – Forward Ed
    Nov 20 at 4:44










  • @ForwardEd, yes and there can also be no In time for a certain date but has a OUT time
    – NoobPro
    Nov 21 at 5:33















up vote
0
down vote

favorite












I have this:



badly formatted table



which is difficult to read, 'I' means time in and 'O' means time out.



I want to transform it like this:



this



I want to align each time in and time out to its respective employee ID and date. Thanks



EDIT



I's and O's in the first table aren't necessarily alternating, there may be 3 I's before its respective O show up.



The result should be:
1. missing values of time in and out should show as blank
2. editable so the user can fill out missing time ins or outs and;
3. the t










share|improve this question
























  • Possible duplicate of How to combine values from multiple rows into a single row in Excel?
    – Scott
    Nov 19 at 3:27










  • Create a pivot, use employee number and date as the rows, and min and max of time for time as the values for time in and time
    – PeterH
    Nov 19 at 14:33










  • can there be multiple ins on the same date? Conversely multiple outs on the same date?
    – Forward Ed
    Nov 20 at 4:44










  • @ForwardEd, yes and there can also be no In time for a certain date but has a OUT time
    – NoobPro
    Nov 21 at 5:33













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have this:



badly formatted table



which is difficult to read, 'I' means time in and 'O' means time out.



I want to transform it like this:



this



I want to align each time in and time out to its respective employee ID and date. Thanks



EDIT



I's and O's in the first table aren't necessarily alternating, there may be 3 I's before its respective O show up.



The result should be:
1. missing values of time in and out should show as blank
2. editable so the user can fill out missing time ins or outs and;
3. the t










share|improve this question















I have this:



badly formatted table



which is difficult to read, 'I' means time in and 'O' means time out.



I want to transform it like this:



this



I want to align each time in and time out to its respective employee ID and date. Thanks



EDIT



I's and O's in the first table aren't necessarily alternating, there may be 3 I's before its respective O show up.



The result should be:
1. missing values of time in and out should show as blank
2. editable so the user can fill out missing time ins or outs and;
3. the t







microsoft-excel worksheet-function microsoft-excel-2016






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 at 1:42

























asked Nov 19 at 3:16









NoobPro

12




12












  • Possible duplicate of How to combine values from multiple rows into a single row in Excel?
    – Scott
    Nov 19 at 3:27










  • Create a pivot, use employee number and date as the rows, and min and max of time for time as the values for time in and time
    – PeterH
    Nov 19 at 14:33










  • can there be multiple ins on the same date? Conversely multiple outs on the same date?
    – Forward Ed
    Nov 20 at 4:44










  • @ForwardEd, yes and there can also be no In time for a certain date but has a OUT time
    – NoobPro
    Nov 21 at 5:33


















  • Possible duplicate of How to combine values from multiple rows into a single row in Excel?
    – Scott
    Nov 19 at 3:27










  • Create a pivot, use employee number and date as the rows, and min and max of time for time as the values for time in and time
    – PeterH
    Nov 19 at 14:33










  • can there be multiple ins on the same date? Conversely multiple outs on the same date?
    – Forward Ed
    Nov 20 at 4:44










  • @ForwardEd, yes and there can also be no In time for a certain date but has a OUT time
    – NoobPro
    Nov 21 at 5:33
















Possible duplicate of How to combine values from multiple rows into a single row in Excel?
– Scott
Nov 19 at 3:27




Possible duplicate of How to combine values from multiple rows into a single row in Excel?
– Scott
Nov 19 at 3:27












Create a pivot, use employee number and date as the rows, and min and max of time for time as the values for time in and time
– PeterH
Nov 19 at 14:33




Create a pivot, use employee number and date as the rows, and min and max of time for time as the values for time in and time
– PeterH
Nov 19 at 14:33












can there be multiple ins on the same date? Conversely multiple outs on the same date?
– Forward Ed
Nov 20 at 4:44




can there be multiple ins on the same date? Conversely multiple outs on the same date?
– Forward Ed
Nov 20 at 4:44












@ForwardEd, yes and there can also be no In time for a certain date but has a OUT time
– NoobPro
Nov 21 at 5:33




@ForwardEd, yes and there can also be no In time for a certain date but has a OUT time
– NoobPro
Nov 21 at 5:33










2 Answers
2






active

oldest

votes

















up vote
0
down vote













Create a Pivot Table from your data with the following configuration:



Pivot



You'll probably also need to format the value as a Time:



format



And you may also want to display the Pivot Table in tabular format to yield the desired result:



tabular



Also turning off the display of Subtotals & Grand Totals:



subtotals



grandtotals



Note that if there are multiple In/Out records per day per employee, this will only show the latest In or Out record (by virtue of aggregating with Max).






share|improve this answer





















  • Hey it works, but i need the result to be editable. Sorry saying it just now, I've edited my post
    – NoobPro
    Nov 20 at 1:44


















up vote
0
down vote













Well i wrote an ugly bit of VBA but it does seem to work. There is room for optimization as I see code repeated. It is currently hard coded to out put in the 7 column 2nd row.



Option Explicit

Sub I_O_single_line()

Dim rng As Range
Dim counter1 As Integer, counter2 As Integer, counter3 As Integer, LastRow As Integer, WriteRow As Integer, HeaderRow As Integer
Dim wkb As Workbook
Dim sht As Worksheet
Dim Arr() As Variant

Set wkb = ActiveWorkbook
Set sht = wkb.Worksheets(1)

'Last row of header row information
'set to 0 if no header row

HeaderRow = 1

'initializing the first row that the sorted data will be written to
WriteRow = HeaderRow + 1

'Finds the last used row
With sht
If Application.WorksheetFunction.CountA(.Cells) <> 0 Then
LastRow = .Cells.Find(What:="*", _
After:=.Range("A1"), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
Else
LastRow = 1
End If
End With

'Resize the array to match your data
ReDim Arr(LastRow - HeaderRow, 4)

'Copy the contents of the source data into an arr
Arr() = Range(Cells(HeaderRow + 1, 1), Cells(LastRow, 4))

'iterate through each row of the source data
For counter1 = 1 To (LastRow - HeaderRow)
'first row of data is potentially a special case
If counter1 = 1 Then
'Write out ID and Date
For counter2 = 1 To 2
Cells(WriteRow, 6 + counter2) = Arr(counter1, counter2)
Next counter2
'Write out Time in appropriate column
If Arr(counter1, 4) = "I" Then
Cells(WriteRow, 6 + 3) = Arr(counter1, 3)
ElseIf Arr(counter1, 4) = "O" Then
Cells(WriteRow, 6 + 4) = Arr(counter1, 3)
WriteRow = WriteRow + 1
End If
'Check to see if ID changed
ElseIf Arr(counter1 - 1, 1) = Arr(counter1, 1) Then
'Check to see if Date has changed
If Arr(counter1 - 1, 2) = Arr(counter1, 2) Then
'Write out time in appropriate column
If Arr(counter1, 4) = "I" Then
'Check if previous entry is a repeat
If Arr(counter1 - 1, 4) = Arr(counter1, 4) Then
'Advance Write a new line
WriteRow = WriteRow + 1
End If
For counter2 = 1 To 3
Cells(WriteRow, 6 + counter2) = Arr(counter1, counter2)
Next counter2
ElseIf Arr(counter1, 4) = "O" Then
'Check if previous entry is a repeat
If Arr(counter1 - 1, 4) = Arr(counter1, 4) Then
'Write ID and Date
For counter2 = 1 To 2
Cells(WriteRow, 6 + counter2) = Arr(counter1, counter2)
Next counter2
End If
Cells(WriteRow, 6 + 4) = Arr(counter1, 3)
WriteRow = WriteRow + 1
End If
'What to do if date has changed
Else
If Arr(counter1 - 1, 4) = "I" Then
WriteRow = WriteRow + 1
End If
'Write ID and Date
For counter2 = 1 To 2
Cells(WriteRow, 6 + counter2) = Arr(counter1, counter2)
Next counter2
'Write out Time in appropriate column
If Arr(counter1, 4) = "I" Then
Cells(WriteRow, 6 + 3) = Arr(counter1, 3)
ElseIf Arr(counter1, 4) = "O" Then
Cells(WriteRow, 6 + 4) = Arr(counter1, 3)
WriteRow = WriteRow + 1
End If
End If
'What to do if ID has change
Else
If Arr(counter1 - 1, 4) = "I" Then
WriteRow = WriteRow + 1
End If
'Write ID and Date
For counter2 = 1 To 2
Cells(WriteRow, 6 + counter2) = Arr(counter1, counter2)
Next counter2
'Write out Time in appropriate column
If Arr(counter1, 4) = "I" Then
Cells(WriteRow, 6 + 3) = Arr(counter1, 3)
ElseIf Arr(counter1, 4) = "O" Then
Cells(WriteRow, 6 + 4) = Arr(counter1, 3)
WriteRow = WriteRow + 1
End If
End If
Next counter1
End Sub


enter image description here






share|improve this answer























  • Hey it works, but the I's and O's in the first table arent necessarily alternating. Sorry saying it just now, I've edited my post
    – NoobPro
    Nov 20 at 1:44











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "3"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1376589%2ffixing-excel-timesheet-by-time-in-and-time-out-per-user-and-date%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote













Create a Pivot Table from your data with the following configuration:



Pivot



You'll probably also need to format the value as a Time:



format



And you may also want to display the Pivot Table in tabular format to yield the desired result:



tabular



Also turning off the display of Subtotals & Grand Totals:



subtotals



grandtotals



Note that if there are multiple In/Out records per day per employee, this will only show the latest In or Out record (by virtue of aggregating with Max).






share|improve this answer





















  • Hey it works, but i need the result to be editable. Sorry saying it just now, I've edited my post
    – NoobPro
    Nov 20 at 1:44















up vote
0
down vote













Create a Pivot Table from your data with the following configuration:



Pivot



You'll probably also need to format the value as a Time:



format



And you may also want to display the Pivot Table in tabular format to yield the desired result:



tabular



Also turning off the display of Subtotals & Grand Totals:



subtotals



grandtotals



Note that if there are multiple In/Out records per day per employee, this will only show the latest In or Out record (by virtue of aggregating with Max).






share|improve this answer





















  • Hey it works, but i need the result to be editable. Sorry saying it just now, I've edited my post
    – NoobPro
    Nov 20 at 1:44













up vote
0
down vote










up vote
0
down vote









Create a Pivot Table from your data with the following configuration:



Pivot



You'll probably also need to format the value as a Time:



format



And you may also want to display the Pivot Table in tabular format to yield the desired result:



tabular



Also turning off the display of Subtotals & Grand Totals:



subtotals



grandtotals



Note that if there are multiple In/Out records per day per employee, this will only show the latest In or Out record (by virtue of aggregating with Max).






share|improve this answer












Create a Pivot Table from your data with the following configuration:



Pivot



You'll probably also need to format the value as a Time:



format



And you may also want to display the Pivot Table in tabular format to yield the desired result:



tabular



Also turning off the display of Subtotals & Grand Totals:



subtotals



grandtotals



Note that if there are multiple In/Out records per day per employee, this will only show the latest In or Out record (by virtue of aggregating with Max).







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 19 at 14:56









Lee Mac

428110




428110












  • Hey it works, but i need the result to be editable. Sorry saying it just now, I've edited my post
    – NoobPro
    Nov 20 at 1:44


















  • Hey it works, but i need the result to be editable. Sorry saying it just now, I've edited my post
    – NoobPro
    Nov 20 at 1:44
















Hey it works, but i need the result to be editable. Sorry saying it just now, I've edited my post
– NoobPro
Nov 20 at 1:44




Hey it works, but i need the result to be editable. Sorry saying it just now, I've edited my post
– NoobPro
Nov 20 at 1:44












up vote
0
down vote













Well i wrote an ugly bit of VBA but it does seem to work. There is room for optimization as I see code repeated. It is currently hard coded to out put in the 7 column 2nd row.



Option Explicit

Sub I_O_single_line()

Dim rng As Range
Dim counter1 As Integer, counter2 As Integer, counter3 As Integer, LastRow As Integer, WriteRow As Integer, HeaderRow As Integer
Dim wkb As Workbook
Dim sht As Worksheet
Dim Arr() As Variant

Set wkb = ActiveWorkbook
Set sht = wkb.Worksheets(1)

'Last row of header row information
'set to 0 if no header row

HeaderRow = 1

'initializing the first row that the sorted data will be written to
WriteRow = HeaderRow + 1

'Finds the last used row
With sht
If Application.WorksheetFunction.CountA(.Cells) <> 0 Then
LastRow = .Cells.Find(What:="*", _
After:=.Range("A1"), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
Else
LastRow = 1
End If
End With

'Resize the array to match your data
ReDim Arr(LastRow - HeaderRow, 4)

'Copy the contents of the source data into an arr
Arr() = Range(Cells(HeaderRow + 1, 1), Cells(LastRow, 4))

'iterate through each row of the source data
For counter1 = 1 To (LastRow - HeaderRow)
'first row of data is potentially a special case
If counter1 = 1 Then
'Write out ID and Date
For counter2 = 1 To 2
Cells(WriteRow, 6 + counter2) = Arr(counter1, counter2)
Next counter2
'Write out Time in appropriate column
If Arr(counter1, 4) = "I" Then
Cells(WriteRow, 6 + 3) = Arr(counter1, 3)
ElseIf Arr(counter1, 4) = "O" Then
Cells(WriteRow, 6 + 4) = Arr(counter1, 3)
WriteRow = WriteRow + 1
End If
'Check to see if ID changed
ElseIf Arr(counter1 - 1, 1) = Arr(counter1, 1) Then
'Check to see if Date has changed
If Arr(counter1 - 1, 2) = Arr(counter1, 2) Then
'Write out time in appropriate column
If Arr(counter1, 4) = "I" Then
'Check if previous entry is a repeat
If Arr(counter1 - 1, 4) = Arr(counter1, 4) Then
'Advance Write a new line
WriteRow = WriteRow + 1
End If
For counter2 = 1 To 3
Cells(WriteRow, 6 + counter2) = Arr(counter1, counter2)
Next counter2
ElseIf Arr(counter1, 4) = "O" Then
'Check if previous entry is a repeat
If Arr(counter1 - 1, 4) = Arr(counter1, 4) Then
'Write ID and Date
For counter2 = 1 To 2
Cells(WriteRow, 6 + counter2) = Arr(counter1, counter2)
Next counter2
End If
Cells(WriteRow, 6 + 4) = Arr(counter1, 3)
WriteRow = WriteRow + 1
End If
'What to do if date has changed
Else
If Arr(counter1 - 1, 4) = "I" Then
WriteRow = WriteRow + 1
End If
'Write ID and Date
For counter2 = 1 To 2
Cells(WriteRow, 6 + counter2) = Arr(counter1, counter2)
Next counter2
'Write out Time in appropriate column
If Arr(counter1, 4) = "I" Then
Cells(WriteRow, 6 + 3) = Arr(counter1, 3)
ElseIf Arr(counter1, 4) = "O" Then
Cells(WriteRow, 6 + 4) = Arr(counter1, 3)
WriteRow = WriteRow + 1
End If
End If
'What to do if ID has change
Else
If Arr(counter1 - 1, 4) = "I" Then
WriteRow = WriteRow + 1
End If
'Write ID and Date
For counter2 = 1 To 2
Cells(WriteRow, 6 + counter2) = Arr(counter1, counter2)
Next counter2
'Write out Time in appropriate column
If Arr(counter1, 4) = "I" Then
Cells(WriteRow, 6 + 3) = Arr(counter1, 3)
ElseIf Arr(counter1, 4) = "O" Then
Cells(WriteRow, 6 + 4) = Arr(counter1, 3)
WriteRow = WriteRow + 1
End If
End If
Next counter1
End Sub


enter image description here






share|improve this answer























  • Hey it works, but the I's and O's in the first table arent necessarily alternating. Sorry saying it just now, I've edited my post
    – NoobPro
    Nov 20 at 1:44















up vote
0
down vote













Well i wrote an ugly bit of VBA but it does seem to work. There is room for optimization as I see code repeated. It is currently hard coded to out put in the 7 column 2nd row.



Option Explicit

Sub I_O_single_line()

Dim rng As Range
Dim counter1 As Integer, counter2 As Integer, counter3 As Integer, LastRow As Integer, WriteRow As Integer, HeaderRow As Integer
Dim wkb As Workbook
Dim sht As Worksheet
Dim Arr() As Variant

Set wkb = ActiveWorkbook
Set sht = wkb.Worksheets(1)

'Last row of header row information
'set to 0 if no header row

HeaderRow = 1

'initializing the first row that the sorted data will be written to
WriteRow = HeaderRow + 1

'Finds the last used row
With sht
If Application.WorksheetFunction.CountA(.Cells) <> 0 Then
LastRow = .Cells.Find(What:="*", _
After:=.Range("A1"), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
Else
LastRow = 1
End If
End With

'Resize the array to match your data
ReDim Arr(LastRow - HeaderRow, 4)

'Copy the contents of the source data into an arr
Arr() = Range(Cells(HeaderRow + 1, 1), Cells(LastRow, 4))

'iterate through each row of the source data
For counter1 = 1 To (LastRow - HeaderRow)
'first row of data is potentially a special case
If counter1 = 1 Then
'Write out ID and Date
For counter2 = 1 To 2
Cells(WriteRow, 6 + counter2) = Arr(counter1, counter2)
Next counter2
'Write out Time in appropriate column
If Arr(counter1, 4) = "I" Then
Cells(WriteRow, 6 + 3) = Arr(counter1, 3)
ElseIf Arr(counter1, 4) = "O" Then
Cells(WriteRow, 6 + 4) = Arr(counter1, 3)
WriteRow = WriteRow + 1
End If
'Check to see if ID changed
ElseIf Arr(counter1 - 1, 1) = Arr(counter1, 1) Then
'Check to see if Date has changed
If Arr(counter1 - 1, 2) = Arr(counter1, 2) Then
'Write out time in appropriate column
If Arr(counter1, 4) = "I" Then
'Check if previous entry is a repeat
If Arr(counter1 - 1, 4) = Arr(counter1, 4) Then
'Advance Write a new line
WriteRow = WriteRow + 1
End If
For counter2 = 1 To 3
Cells(WriteRow, 6 + counter2) = Arr(counter1, counter2)
Next counter2
ElseIf Arr(counter1, 4) = "O" Then
'Check if previous entry is a repeat
If Arr(counter1 - 1, 4) = Arr(counter1, 4) Then
'Write ID and Date
For counter2 = 1 To 2
Cells(WriteRow, 6 + counter2) = Arr(counter1, counter2)
Next counter2
End If
Cells(WriteRow, 6 + 4) = Arr(counter1, 3)
WriteRow = WriteRow + 1
End If
'What to do if date has changed
Else
If Arr(counter1 - 1, 4) = "I" Then
WriteRow = WriteRow + 1
End If
'Write ID and Date
For counter2 = 1 To 2
Cells(WriteRow, 6 + counter2) = Arr(counter1, counter2)
Next counter2
'Write out Time in appropriate column
If Arr(counter1, 4) = "I" Then
Cells(WriteRow, 6 + 3) = Arr(counter1, 3)
ElseIf Arr(counter1, 4) = "O" Then
Cells(WriteRow, 6 + 4) = Arr(counter1, 3)
WriteRow = WriteRow + 1
End If
End If
'What to do if ID has change
Else
If Arr(counter1 - 1, 4) = "I" Then
WriteRow = WriteRow + 1
End If
'Write ID and Date
For counter2 = 1 To 2
Cells(WriteRow, 6 + counter2) = Arr(counter1, counter2)
Next counter2
'Write out Time in appropriate column
If Arr(counter1, 4) = "I" Then
Cells(WriteRow, 6 + 3) = Arr(counter1, 3)
ElseIf Arr(counter1, 4) = "O" Then
Cells(WriteRow, 6 + 4) = Arr(counter1, 3)
WriteRow = WriteRow + 1
End If
End If
Next counter1
End Sub


enter image description here






share|improve this answer























  • Hey it works, but the I's and O's in the first table arent necessarily alternating. Sorry saying it just now, I've edited my post
    – NoobPro
    Nov 20 at 1:44













up vote
0
down vote










up vote
0
down vote









Well i wrote an ugly bit of VBA but it does seem to work. There is room for optimization as I see code repeated. It is currently hard coded to out put in the 7 column 2nd row.



Option Explicit

Sub I_O_single_line()

Dim rng As Range
Dim counter1 As Integer, counter2 As Integer, counter3 As Integer, LastRow As Integer, WriteRow As Integer, HeaderRow As Integer
Dim wkb As Workbook
Dim sht As Worksheet
Dim Arr() As Variant

Set wkb = ActiveWorkbook
Set sht = wkb.Worksheets(1)

'Last row of header row information
'set to 0 if no header row

HeaderRow = 1

'initializing the first row that the sorted data will be written to
WriteRow = HeaderRow + 1

'Finds the last used row
With sht
If Application.WorksheetFunction.CountA(.Cells) <> 0 Then
LastRow = .Cells.Find(What:="*", _
After:=.Range("A1"), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
Else
LastRow = 1
End If
End With

'Resize the array to match your data
ReDim Arr(LastRow - HeaderRow, 4)

'Copy the contents of the source data into an arr
Arr() = Range(Cells(HeaderRow + 1, 1), Cells(LastRow, 4))

'iterate through each row of the source data
For counter1 = 1 To (LastRow - HeaderRow)
'first row of data is potentially a special case
If counter1 = 1 Then
'Write out ID and Date
For counter2 = 1 To 2
Cells(WriteRow, 6 + counter2) = Arr(counter1, counter2)
Next counter2
'Write out Time in appropriate column
If Arr(counter1, 4) = "I" Then
Cells(WriteRow, 6 + 3) = Arr(counter1, 3)
ElseIf Arr(counter1, 4) = "O" Then
Cells(WriteRow, 6 + 4) = Arr(counter1, 3)
WriteRow = WriteRow + 1
End If
'Check to see if ID changed
ElseIf Arr(counter1 - 1, 1) = Arr(counter1, 1) Then
'Check to see if Date has changed
If Arr(counter1 - 1, 2) = Arr(counter1, 2) Then
'Write out time in appropriate column
If Arr(counter1, 4) = "I" Then
'Check if previous entry is a repeat
If Arr(counter1 - 1, 4) = Arr(counter1, 4) Then
'Advance Write a new line
WriteRow = WriteRow + 1
End If
For counter2 = 1 To 3
Cells(WriteRow, 6 + counter2) = Arr(counter1, counter2)
Next counter2
ElseIf Arr(counter1, 4) = "O" Then
'Check if previous entry is a repeat
If Arr(counter1 - 1, 4) = Arr(counter1, 4) Then
'Write ID and Date
For counter2 = 1 To 2
Cells(WriteRow, 6 + counter2) = Arr(counter1, counter2)
Next counter2
End If
Cells(WriteRow, 6 + 4) = Arr(counter1, 3)
WriteRow = WriteRow + 1
End If
'What to do if date has changed
Else
If Arr(counter1 - 1, 4) = "I" Then
WriteRow = WriteRow + 1
End If
'Write ID and Date
For counter2 = 1 To 2
Cells(WriteRow, 6 + counter2) = Arr(counter1, counter2)
Next counter2
'Write out Time in appropriate column
If Arr(counter1, 4) = "I" Then
Cells(WriteRow, 6 + 3) = Arr(counter1, 3)
ElseIf Arr(counter1, 4) = "O" Then
Cells(WriteRow, 6 + 4) = Arr(counter1, 3)
WriteRow = WriteRow + 1
End If
End If
'What to do if ID has change
Else
If Arr(counter1 - 1, 4) = "I" Then
WriteRow = WriteRow + 1
End If
'Write ID and Date
For counter2 = 1 To 2
Cells(WriteRow, 6 + counter2) = Arr(counter1, counter2)
Next counter2
'Write out Time in appropriate column
If Arr(counter1, 4) = "I" Then
Cells(WriteRow, 6 + 3) = Arr(counter1, 3)
ElseIf Arr(counter1, 4) = "O" Then
Cells(WriteRow, 6 + 4) = Arr(counter1, 3)
WriteRow = WriteRow + 1
End If
End If
Next counter1
End Sub


enter image description here






share|improve this answer














Well i wrote an ugly bit of VBA but it does seem to work. There is room for optimization as I see code repeated. It is currently hard coded to out put in the 7 column 2nd row.



Option Explicit

Sub I_O_single_line()

Dim rng As Range
Dim counter1 As Integer, counter2 As Integer, counter3 As Integer, LastRow As Integer, WriteRow As Integer, HeaderRow As Integer
Dim wkb As Workbook
Dim sht As Worksheet
Dim Arr() As Variant

Set wkb = ActiveWorkbook
Set sht = wkb.Worksheets(1)

'Last row of header row information
'set to 0 if no header row

HeaderRow = 1

'initializing the first row that the sorted data will be written to
WriteRow = HeaderRow + 1

'Finds the last used row
With sht
If Application.WorksheetFunction.CountA(.Cells) <> 0 Then
LastRow = .Cells.Find(What:="*", _
After:=.Range("A1"), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
Else
LastRow = 1
End If
End With

'Resize the array to match your data
ReDim Arr(LastRow - HeaderRow, 4)

'Copy the contents of the source data into an arr
Arr() = Range(Cells(HeaderRow + 1, 1), Cells(LastRow, 4))

'iterate through each row of the source data
For counter1 = 1 To (LastRow - HeaderRow)
'first row of data is potentially a special case
If counter1 = 1 Then
'Write out ID and Date
For counter2 = 1 To 2
Cells(WriteRow, 6 + counter2) = Arr(counter1, counter2)
Next counter2
'Write out Time in appropriate column
If Arr(counter1, 4) = "I" Then
Cells(WriteRow, 6 + 3) = Arr(counter1, 3)
ElseIf Arr(counter1, 4) = "O" Then
Cells(WriteRow, 6 + 4) = Arr(counter1, 3)
WriteRow = WriteRow + 1
End If
'Check to see if ID changed
ElseIf Arr(counter1 - 1, 1) = Arr(counter1, 1) Then
'Check to see if Date has changed
If Arr(counter1 - 1, 2) = Arr(counter1, 2) Then
'Write out time in appropriate column
If Arr(counter1, 4) = "I" Then
'Check if previous entry is a repeat
If Arr(counter1 - 1, 4) = Arr(counter1, 4) Then
'Advance Write a new line
WriteRow = WriteRow + 1
End If
For counter2 = 1 To 3
Cells(WriteRow, 6 + counter2) = Arr(counter1, counter2)
Next counter2
ElseIf Arr(counter1, 4) = "O" Then
'Check if previous entry is a repeat
If Arr(counter1 - 1, 4) = Arr(counter1, 4) Then
'Write ID and Date
For counter2 = 1 To 2
Cells(WriteRow, 6 + counter2) = Arr(counter1, counter2)
Next counter2
End If
Cells(WriteRow, 6 + 4) = Arr(counter1, 3)
WriteRow = WriteRow + 1
End If
'What to do if date has changed
Else
If Arr(counter1 - 1, 4) = "I" Then
WriteRow = WriteRow + 1
End If
'Write ID and Date
For counter2 = 1 To 2
Cells(WriteRow, 6 + counter2) = Arr(counter1, counter2)
Next counter2
'Write out Time in appropriate column
If Arr(counter1, 4) = "I" Then
Cells(WriteRow, 6 + 3) = Arr(counter1, 3)
ElseIf Arr(counter1, 4) = "O" Then
Cells(WriteRow, 6 + 4) = Arr(counter1, 3)
WriteRow = WriteRow + 1
End If
End If
'What to do if ID has change
Else
If Arr(counter1 - 1, 4) = "I" Then
WriteRow = WriteRow + 1
End If
'Write ID and Date
For counter2 = 1 To 2
Cells(WriteRow, 6 + counter2) = Arr(counter1, counter2)
Next counter2
'Write out Time in appropriate column
If Arr(counter1, 4) = "I" Then
Cells(WriteRow, 6 + 3) = Arr(counter1, 3)
ElseIf Arr(counter1, 4) = "O" Then
Cells(WriteRow, 6 + 4) = Arr(counter1, 3)
WriteRow = WriteRow + 1
End If
End If
Next counter1
End Sub


enter image description here







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 22 at 16:15

























answered Nov 19 at 16:02









Forward Ed

427213




427213












  • Hey it works, but the I's and O's in the first table arent necessarily alternating. Sorry saying it just now, I've edited my post
    – NoobPro
    Nov 20 at 1:44


















  • Hey it works, but the I's and O's in the first table arent necessarily alternating. Sorry saying it just now, I've edited my post
    – NoobPro
    Nov 20 at 1:44
















Hey it works, but the I's and O's in the first table arent necessarily alternating. Sorry saying it just now, I've edited my post
– NoobPro
Nov 20 at 1:44




Hey it works, but the I's and O's in the first table arent necessarily alternating. Sorry saying it just now, I've edited my post
– NoobPro
Nov 20 at 1:44


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1376589%2ffixing-excel-timesheet-by-time-in-and-time-out-per-user-and-date%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Plaza Victoria

In PowerPoint, is there a keyboard shortcut for bulleted / numbered list?

How to put 3 figures in Latex with 2 figures side by side and 1 below these side by side images but in...