Scan In Scan Out

MightyGhost

New Member
Joined
Nov 20, 2021
Messages
1
Office Version
  1. 365
Platform
  1. Windows
Morning

I am new to VBA programming and what I am trying to do is scan a barcode that is already in a cell in Column E and have a scan in time and a scan out time in columns I and J. But then if that same barcode gets taken out again it be registered on a new row so I can have multiple scans of the same barcode I have attached a test sheet it would be really helpful if can assist
Here is the code that I am trying to edit and use

VBA Code:
Sub access()
Dim barcode As String
Dim rng As Range
Dim rownumber, erow As Long
Dim r As Long
Dim Total As Double
Dim Timein As Date
Dim Timeout As Date
Dim ws As Worksheet
Dim name As String
erow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row + 1
Set ws = Sheet1
barcode = Sheet1.Cells(2, 1)

If barcode (not equal)"" Then
    With Sheet1.Range("a4:a10000")
    Set rng = .Find(what:=barcode, _
    LookIn:=xlFormulas, LookAt:=xlWhole, SearchOrder:=xlByRows, _
    searchdirection:=xlNext, MatchCase:=False, SearchFormat:=False)
    If rng Is Nothing Then
restart:
        Sheet1.Cells(erow, 1).Select
        ActiveCell.Value = barcode
        ActiveCell.NumberFormat = "@"
        ActiveCell.Offset(0, 1).Select
        ActiveCell.Value = Date & "  " & Time
        ActiveCell.NumberFormat = "d/m/yyyy h:mm AM/PM"
        ActiveSheet.Cells(2, 1) = ""
        GoTo ende
    Else

    If Not rng Is Nothing Then
        rownumber = rng.Row
        If Cells(rownumber, 3) not equal "" Then
            For r = rownumber To erow
                If Cells(r, 1) = barcode And Cells(r, 3) = "" Then
                    rownumber = r
                    GoTo enterdata
                End If
            Next r
            GoTo restart
        End If
enterdata:
    ActiveSheet.Cells(rownumber, 1).Select
    ActiveCell.Offset(0, 2).Select
    ActiveCell.Value = Date & "  " & Time
    ActiveCell.NumberFormat = "m/d/yyyy h:mm AM/PM"
    Timein = CDate(Cells(rownumber, 2).Value)
    Timeout = CDate(Cells(rownumber, 3).Value)
   
   
   
    Sheet1.Cells(2, 1) = ""
    End If
      
    End If
    End With
    Sheet1.Cells(2, 1) = ""
       
   '
   
End If
ende:
Sheet1.Activate
Sheet1.Cells(2, 1).Select

End Sub
 
Last edited by a moderator:

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,152,488
Messages
5,770,380
Members
425,613
Latest member
martinijr

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
Top