qpywsqp,
Sample results with the updated Worksheet_Change Event:
Sheet1
| A | B | C | D | E | F | G |
Code | Name | Contact | Email | Time In | Time Out | Time In | |
MC10008 | Jacky | | | | | | |
MC10080 | Rebecca | | | | | | |
PC10001 | Rachel | | | | | | |
PC10100 | Jeffrey | | | | | | |
PC10108 | Steve | | | | | | |
MC10988 | Rosy | | | | | | |
PC10945 | Johnson | | | | | | |
MC10884 | Jackson | | | | | | |
MC10886 | Ravy | | | | | | |
QPYWSQP | | | | | | | |
| | | | | | | |
<colgroup><col style="font-weight:bold; width:30px; "><col style="width:81px;"><col style="width:76px;"><col style="width:71px;"><col style="width:59px;"><col style="width:110px;"><col style="width:110px;"><col style="width:110px;"></colgroup><tbody>
[TD="bgcolor: #cacaca, align: center"]1[/TD]
[TD="bgcolor: #cacaca, align: center"]2[/TD]
[TD="bgcolor: #cacaca, align: center"]3[/TD]
[TD="align: right"]2/4/2013 8:41[/TD]
[TD="align: right"]2/4/2013 8:43[/TD]
[TD="bgcolor: #cacaca, align: center"]4[/TD]
[TD="bgcolor: #cacaca, align: center"]5[/TD]
[TD="align: right"]2/4/2013 8:42[/TD]
[TD="bgcolor: #cacaca, align: center"]6[/TD]
[TD="bgcolor: #cacaca, align: center"]7[/TD]
[TD="bgcolor: #cacaca, align: center"]8[/TD]
[TD="bgcolor: #cacaca, align: center"]9[/TD]
[TD="bgcolor: #cacaca, align: center"]10[/TD]
[TD="bgcolor: #cacaca, align: center"]11[/TD]
[TD="align: right"]2/4/2013 8:42[/TD]
[TD="align: right"]2/4/2013 8:43[/TD]
[TD="bgcolor: #cacaca, align: center"]12[/TD]
</tbody>
Excel tables to the web >> Excel Jeanie HTML 4
Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).
1. Copy the below code, by highlighting the code and pressing the keys
CTRL +
C
2. Select the worksheet in which your code is to run
3. Right click on the sheet tab and choose
View Code, to open the Visual Basic Editor
4. Where the cursor is flashing, paste the code by pressing the keys
CTRL +
V
5. Press the keys
ALT +
Q to exit the Editor, and return to Excel
Code:
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
' hiker95, 02/04/2013
' http://www.mrexcel.com/forum/excel-questions/672492-scan-barcode-excel-date-time-stamp-out.html
If Intersect(Target, Range("A2:A3000")) Is Nothing Then Exit Sub
If Target.Count > 1 Then Exit Sub
If Target = "" Then Exit Sub
Dim lc As Long, fr As Long, n As Long, nr As Long
With Application
.EnableEvents = False
.ScreenUpdating = False
n = Application.CountIf(Columns(1), Cells(Target.Row, 1))
If n = 1 Then
lc = Cells(Target.Row, Columns.Count).End(xlToLeft).Column
If lc <= 5 Then
Cells(Target.Row, 5) = Format(Now, "m/d/yyyy h:mm")
ElseIf lc > 4 Then
Cells(Target.Row, lc + 1) = Format(Now, "m/d/yyyy h:mm")
End If
Else
fr = 0
On Error Resume Next
fr = Application.Match(Cells(Target.Row, 1), Columns(1), 0)
On Error GoTo 0
If fr > 0 Then
lc = Cells(fr, Columns.Count).End(xlToLeft).Column
If lc < 5 Then
Cells(fr, 5) = Format(Now, "m/d/yyyy h:mm")
ElseIf lc > 4 Then
Cells(fr, lc + 1) = Format(Now, "m/d/yyyy h:mm")
End If
Target.ClearContents
End If
End If
On Error Resume Next
Me.Range("A1", Range("A" & Rows.Count).End(xlUp)).SpecialCells(xlCellTypeBlanks).EntireRow.Delete
On Error GoTo 0
nr = Me.Range("A" & Rows.Count).End(xlUp).Offset(1).Row
Me.Cells(nr, 1).Select
.EnableEvents = True
.ScreenUpdating = True
End With
End Sub
Before you use the macro with Excel 2007 or newer, save your workbook, Save As, a macro enabled workbook with the file extension
.xlsm
Remember - you can only have one Worksheet_Change Event within a worksheet.
Then scan in the Code as before.