WHAT I CURRENTLY HAVE:
Here is a screenshot of my current excel spreadsheet:
[/URL][/IMG]
Here is a copy of the code I am currently using:
Currently the way the excel sheet works: if you enter a value into column A and it is an original piece of data, it will add a date/time stamp onto the row in column C. If you repeat that same piece of data again further down the column, it will recognize that it is a duplicate and add a "time out" in column D on the row that this same piece of data was already entered. It will also delete that whole row of the duplicate too.
WHAT I WOULD LIKE MY EXCEL SHEET TO DO:
This is how I would like my excel sheet set up:
[/URL][/IMG]
Columns A and B would be data input either via keyboard or barcode scanner. Column C would be "Column A/Column B" as to make a unique number combination. Column A is employee ID number and Column B is Manufacturing Order number. The whole goal of having that Column C is so that you have a unique number tying that employee to a certain job. The main reason is that you can have several employees working on the same MO, but only one MO can be worked by any given employee at a time.
I have found what I thought to be a solution by entering an excel forumla to calculate that "Column A/Column B" but apparently excel forumlas negate the VBA code of the same cell. So I need VBA to automatically calculate column C after BOTH column A and column B have been entered, and this leading to the time stamp being placed.
Hopefully I explained this well enough, and any help would be greatly appreciated! Thanks!
Here is a screenshot of my current excel spreadsheet:
Here is a copy of the code I am currently using:
Code:
Option ExplicitPrivate Sub Worksheet_Change(ByVal Target As Range)
' hiker95, 12/18/2012
' 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 = 1 Then
Cells(Target.Row, lc + 2) = Format(Now, "m/d/yyyy h:mm")
ElseIf lc > 2 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 = 1 Then
Cells(fr, lc + 2) = Format(Now, "m/d/yyyy h:mm")
ElseIf lc > 2 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
Currently the way the excel sheet works: if you enter a value into column A and it is an original piece of data, it will add a date/time stamp onto the row in column C. If you repeat that same piece of data again further down the column, it will recognize that it is a duplicate and add a "time out" in column D on the row that this same piece of data was already entered. It will also delete that whole row of the duplicate too.
WHAT I WOULD LIKE MY EXCEL SHEET TO DO:
This is how I would like my excel sheet set up:
Columns A and B would be data input either via keyboard or barcode scanner. Column C would be "Column A/Column B" as to make a unique number combination. Column A is employee ID number and Column B is Manufacturing Order number. The whole goal of having that Column C is so that you have a unique number tying that employee to a certain job. The main reason is that you can have several employees working on the same MO, but only one MO can be worked by any given employee at a time.
I have found what I thought to be a solution by entering an excel forumla to calculate that "Column A/Column B" but apparently excel forumlas negate the VBA code of the same cell. So I need VBA to automatically calculate column C after BOTH column A and column B have been entered, and this leading to the time stamp being placed.
Hopefully I explained this well enough, and any help would be greatly appreciated! Thanks!