0

I'm trying to use a macro to crate a In/Out register for bar codes and i'm using a code i found online. The problem is that when I insert a barcode, an error "91" pops up and highlights the line ActiveSheet.Range("a4:a150").Find("").Select Im totally new to the coding world and have no idea whats wrong. would appreciate the help!

Sub access()
Dim barcode As String
Dim rng As Range
Dim foundVal As Range
Dim diff As Double
Dim rownumber As Long

barcode = ActiveSheet.Cells(2, 1)
If barcode <> "" Then
    Set rng = ActiveSheet.Range("a4:a150").Find(What:=barcode, _
    LookIn:=xlFormulas, LookAt:=xlWhole, SearchOrder:=xlByRows, _
    SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
    If rng Is Nothing Then
ActiveSheet.Range("a4:a150").Find("").Select
ActiveCell.Value = barcode
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = Date & "  " & Time
ActiveCell.NumberFormat = "d/m/yyyy h:mm:ss AM/PM"
ActiveSheet.Cells(2, 1) = ""
    Else
        rownumber = rng.Row
        ActiveSheet.Range(Cells(rownumber, 1), Cells(rownumber, 10)).Find("").Select
        ActiveCell.Value = Date & "  " & Time
        ActiveCell.NumberFormat = "d/m/yyyy h:mm:ss AM/PM"
        ActiveSheet.Cells(2, 1) = ""
    End If
End If
ActiveSheet.Cells(2, 1).Select

End Sub

1 Answers1

0

That line will throw an error if there are no empty cells in the range.

SendETHToThisAddress
  • 2,756
  • 7
  • 29
  • 54