Hi,
This is my first thread, so if there is anything I am doing wrong please feel free to let me know.
I have a really simple VBA code to be able to scan a code bar, check it with an inventory list and copy the information in a 3rd sheet to control sells.
I am trying to implement a simple code to check if the Barcode has already been sold and to give me back a message if so. If not, continue with the normal code, but I am not sure in which part of my code (Macro1) should i call Macro 2 for the implementation and check.
Code in Sheet Scan :
Code in Macro 1:
Code in Macro 2 :
At some point I will like to transform sheet 1 into a simple interface in which you click, use the barcode scanner and press enter, but I first need to have the basic code working.
I studied some VBA years ago but never got it to use until this moment, and I am really rusty. There is a big chnace that the code could be so more efficient, but this is the best I got at the moment.
Thank you for any help and advice you can provide me!
This is my first thread, so if there is anything I am doing wrong please feel free to let me know.
I have a really simple VBA code to be able to scan a code bar, check it with an inventory list and copy the information in a 3rd sheet to control sells.
I am trying to implement a simple code to check if the Barcode has already been sold and to give me back a message if so. If not, continue with the normal code, but I am not sure in which part of my code (Macro1) should i call Macro 2 for the implementation and check.
Code in Sheet Scan :
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Me.Range("C2")) Is Nothing Then
Call receive
Application.EnableEvents = True
End If
End Sub
Code in Macro 1:
VBA Code:
Sub receive()
Dim barcode As String
Dim rng As Range
Dim rown, lrow As Long
Dim qty As Long
barcode = Tabelle1.Cells(2, 3)
Tabelle2.Activate
'is there a barcode
If barcode = "" Then Exit Sub
If barcode <> "" Then
Set rng = Tabelle2.Columns("A:A").Find(what:=barcode, _
LookIn:=xlFormulas, LookAt:=xlWhole, SearchOrder:=xlByRows, _
searchdirection:=xlNext, MatchCase:=False, SearchFormat:=False)
If rng Is Nothing Then
MsgBox "Barcode nicht gefunden"
GoTo ende
Else
e
rown = rng.Row
If barcode = "" Then Exit Sub
If barcode <> "" Then
Tabelle2.Cells(rown, 8).Value = Tabelle2.Cells(rown, 8).Value
Tabelle2.Range(Cells(rown, 2), Cells(rown, 7)).Copy
Tabelle3.Activate
lrow = Tabelle3.Cells(Rows.Count, 2).End(xlUp).Row + 1
Tabelle3.Cells(lrow, 2).PasteSpecial
Tabelle3.Cells(lrow, 1).Value = barcode
Tabelle3.Cells(lrow, 8) = Date & " " & Time
Tabelle3.Cells(lrow, 8).NumberFormat = "m/d/yyyy h:mm"
MsgBox "Registered"
GoTo ende
End If
End If
End If
ende:
'turn off the marching ants
Application.CutCopyMode = False
Tabelle1.Activate
Tabelle1.Cells(2, 3).ClearContents
ActiveWorkbook.Sheets("scan").Activate
Sheets("scan").Range("C2").Select '(and activate)
End Sub
VBA Code:
Sub TestForDuplicates()
Dim rng As Range
'Store Range to search through
Set rng = Range("A2:A3")
'Test Range for Duplicates
If Evaluate(Replace("NOT(AND((COUNTIF(@,@)=1)))", "@", rng.Address)) = True Then
MsgBox "Product already sold"
End Sub
At some point I will like to transform sheet 1 into a simple interface in which you click, use the barcode scanner and press enter, but I first need to have the basic code working.
I studied some VBA years ago but never got it to use until this moment, and I am really rusty. There is a big chnace that the code could be so more efficient, but this is the best I got at the moment.
Thank you for any help and advice you can provide me!