I am very new to VBA and need it to perform a series of things in excel.
I have a spreadsheet with over 10000 rows and need to search it using InputBox (UPC field, input is from a barcode scanner)
Once it's found, I need it to select the row of the found cell, copy it, and paste it to another sheet.
This process should loop until the user cancels the InputBox
I have successfully done this, but it seems very inconsistent; it routinely gives me an error on the SelectCells.Select line, but not every time.
Any help would be greatly GREATLY appreciated.
This is what I have so far:
Sub Scan()
Do Until IsEmpty(ActiveCell)
Dim Barcode As Double
Barcode = InputBox("Scan Barcode")
Dim ws As Worksheet
Dim SelectCells As Range
Dim xcell As Object
Set ws = Worksheets("Sheet1")
For Each xcell In ws.UsedRange.Cells
If xcell.Value = Barcode Then
If SelectCells Is Nothing Then
Set SelectCells = Range(xcell.Address)
Else
Set SelectCells = Union(SelectCells, Range(xcell.Address))
End If
End If
Next
SelectCells.Select
Set SelectCells = Nothing
ActiveCell.Rows("1:1").EntireRow.Select
Selection.Copy
Sheets("Sheet2").Select
ActiveSheet.Paste
Sheets("Sheet1").Select
Loop
End Sub