By: Lutfor Rahman Shimanto

In reply to NC.

Hello NC

Thanks for sharing your requirements. You wanted a setup not to overwrite the existing entry but to create a new entry timestamp when an item is checked in or out more than once.

I am delighted to inform you that I have developed an Excel VBA Sub-procedure to fulfil your requirements. So, follow these steps:

1. Press Alt+F11 to the VBA Editor window.

2. Click on Insert followed by Module.

3. Insert the following code in the module and Run.

Sub DuplicateCheckInAndOut()

Dim ws As Worksheet
Dim lastRow As Long
Dim searchValue As Variant
Dim cellB As Range
Dim foundCell As Range
Dim loopingRange As Range
Dim foundInMiddle As Boolean

Set ws = ThisWorkbook.Sheets("Sheet1")

lastRow = ws.Cells(ws.Rows.Count, "B").End(xlUp).Row

searchValue = ws.Range("C4").Value

If lastRow < 9 Then lastRow = 9

Set loopingRange = ws.Range("B9:B" & lastRow)
Set foundCell = loopingRange.Find(What:=searchValue, LookIn:=xlValues, LookAt:=xlWhole)

If foundCell Is Nothing Then
If lastRow = 9 Then
ws.Cells(lastRow, "B").Value = searchValue
ws.Cells(lastRow, "C").Value = Date & " " & Time
ws.Cells(lastRow, "C").NumberFormat = "m/d/yyyy h:mm AM/PM"
Else
ws.Cells(lastRow + 1, "B").Value = searchValue
ws.Cells(lastRow + 1, "C").Value = Date & " " & Time
ws.Cells(lastRow + 1, "C").NumberFormat = "m/d/yyyy h:mm AM/PM"
End If

Exit Sub

End If

For Each cellB In loopingRange

If cellB.Value = searchValue Then
If IsEmpty(cellB.Offset(0, 2).Value) Then
cellB.Offset(0, 2).Value = Date & " " & Time
cellB.Offset(0, 2).NumberFormat = "m/d/yyyy h:mm AM/PM"
foundInMiddle = False
Else
If cellB.Row = lastRow Then
ws.Cells(lastRow + 1, "B").Value = searchValue
ws.Cells(lastRow + 1, "C").Value = Date & " " & Time
ws.Cells(lastRow + 1, "C").NumberFormat = "m/d/yyyy h:mm AM/PM"
Else
foundInMiddle = True
End If
End If
End If

Next cellB

If foundInMiddle = True Then
ws.Cells(lastRow + 1, "B").Value = searchValue
ws.Cells(lastRow + 1, "C").Value = Date & " " & Time
ws.Cells(lastRow + 1, "C").NumberFormat = "m/d/yyyy h:mm AM/PM"
End If

End Sub

After inserting the bar code and running the sub-procedure, you will see an output like the following GIF.

Hopefully, the idea will help you to reach your goal. I have attached the solution workbook. Good luck.

DOWNLOAD SOLUTION WORKBOOK

Regards
Lutfor Rahman Shimanto
Excel & VBA Developer
ExcelDemy