Track Item with location In/Out

GBPPE

New Member
Joined
Feb 28, 2022
Messages
4
Office Version
  1. 365
Platform
  1. Windows
I have created a Macro to track an item with barcode entry at a location with barcode entry and record the track in and track out time.
It starts by clicking the Scan Barcode button.
If the item has not already been entered it will add that item. Track in time
If the item has been entered it will add Track out time.
If the item is entered again then a new line is added with Track in time.

Now for the problem; When I try to track the item out for the second time it does not add track out time. Instead it creates another entry row with track in time.

Here are my screen shots and Thank You for your help.
1646083276559.png
1646083414807.png

1646083553865.png

1646083618359.png
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
I am adding the XL2BB to see if that helps with some answers. Thanks again.
Proof Tracking test - Copy.xlsm
ABCD
1
2Proof IdLocationInOut
31232r3/1/2022 9:49 AM3/1/2022 9:50 AM
4456r3/1/2022 9:49 AM3/1/2022 11:21 AM
5456t3/1/2022 11:21 AM
6456t3/1/2022 11:21 AM
7
8
Sheet1
 
Upvote 0
Seems like I need a second range to start after the active cell so that it keeps looking for the next empty Out and fills it with a time stamp instead of creating another new line. I don't know how to do that step or where to place it in the code. Any ideas?? Something like After ActiveCell repeat the code. Kind of a loop I guess. Any ideas??
 
Upvote 0
does this do what you're after
VBA Code:
Sub InOut()
    Dim barcode As String, location As String
    Dim rng As Range, nextRow As Long
    
barcode = InputBox("Scan Barcode", "Proof Tracking Wizard", "")

Set rng = Sheet1.Columns("A:A").Find(What:=barcode, LookIn:=xlValues, _
    LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlPrevious, _
    MatchCase:=False, SearchFormat:=False)
' if exists
If Not rng Is Nothing Then
    If rng.Offset(, 3) = "" Then
        rng.Offset(, 3) = Now
        rng.Offset(, 3).NumberFormat = "m/d/yyy h:mm AM/PM"
        Exit Sub
    End If
End If
' if doesn't exist or already out
location = InputBox("Please Input a Location", "Proof Tracking Wizard", "")
nextRow = Sheet1.Range("A" & Rows.Count).End(xlUp).Row + 1
With Sheet1.Cells(nextRow, 1)
    .Value = barcode
    .Offset(, 1) = location
    .Offset(, 2) = Now
    .Offset(, 2).NumberFormat = "m/d/yyy h:mm AM/PM"
End With
End Sub
 
Upvote 0
Solution
does this do what you're after
VBA Code:
Sub InOut()
    Dim barcode As String, location As String
    Dim rng As Range, nextRow As Long
   
barcode = InputBox("Scan Barcode", "Proof Tracking Wizard", "")

Set rng = Sheet1.Columns("A:A").Find(What:=barcode, LookIn:=xlValues, _
    LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlPrevious, _
    MatchCase:=False, SearchFormat:=False)
' if exists
If Not rng Is Nothing Then
    If rng.Offset(, 3) = "" Then
        rng.Offset(, 3) = Now
        rng.Offset(, 3).NumberFormat = "m/d/yyy h:mm AM/PM"
        Exit Sub
    End If
End If
' if doesn't exist or already out
location = InputBox("Please Input a Location", "Proof Tracking Wizard", "")
nextRow = Sheet1.Range("A" & Rows.Count).End(xlUp).Row + 1
With Sheet1.Cells(nextRow, 1)
    .Value = barcode
    .Offset(, 1) = location
    .Offset(, 2) = Now
    .Offset(, 2).NumberFormat = "m/d/yyy h:mm AM/PM"
End With
End Sub
That works great! Thank You Very Very Much for the help!
 
Upvote 0

Forum statistics

Threads
1,215,706
Messages
6,126,332
Members
449,308
Latest member
Ronaldj

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top