I am trying to create a Macro for inventory where essentially, Sheet 1 has all the information including barcode #, product name, and product size in rows. In Sheet 2 I have a button that, when clicked, allows me to scan a barcode of a product in my hand.
What I want is that when the barcode that I scan matches one of the barcodes in Sheet 1, all the other information pertaining to that product gets copied over into Sheet 2, or another sheet. I'm not sure which would be easier. Right now the code that I have only adds some additional information next to the barcode that was matched. I'm not sure how to add that information as well as the original information from sheet 1 to a new sheet.
Private Sub CommandButton1_Click()
Dim MatchRow As Variant
Dim code As Variant
Dim matchedCell As Range
barcode = InputBox("Please scan a barcode and hit enter if you need to")
' verify that there is a successful match in the searched range
Set Shta = ActiveWorkbook.Worksheets("Sheet1")
Set Shtb = ActiveWorkbook.Worksheets("Sheet2")
Set Sheet1Range = Sheet1.Range("D2:D108")
If Not IsError(Application.Match(barcode, Sheet1Range, 0)) Then
MatchRow = Application.Match(barcode, Sheet1Range, 0) '<-- get the row number
MatchCatalog = MatchRow + 1
Set matchedCell = Range("D" & MatchCatalog) '<-- set the range (add 1 row since you are starting from row 2)
matchedCell.Offset(0, 2).Value = Now
matchedCell.Offset(0, 3).Value = MatchCatalog
matchedCell.Offset(0, 4).Value = barcode
'option 2: without setting the range
Range("AE" & MatchRow).Offset(1, 2).Value = Now
End If
End Sub
Thanks in advance! Even some help on how to copy data from an entire row into a sheet would be helpful as a start.
You can import your information with a VLOOKUP
or INDEX(MATCH())
depending on how your data is set up. You can just use the macro to only drop your barcode
into a cell. This will be the look up value (first criteria) in your VLOOKUP
The below will put your barcode on A1
Private Sub CommandButton1_Click()
Dim Barcode
barcode = InputBox("Please scan a barcode and hit enter if you need to")
ThisWorkbook.Sheets("Sheet2").Range("A1") = Barcode
End Sub
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.