I am trying to write some VBA code that will take the first value in a list of unique values in column A on sheet2 and search for it against the unique values in column A on sheet1. Once found, it will then update the cell 6 to the right of the active cell on sheet1 with the value adjacent to the unique code in sheet2. It will continue, running down the rest of the list in sheet2 until it reaches a blank cell.
I've managed to get the code to find the unique values and then update the cell 6 to the right by adding 1, but I can't work out the other bit:
Private Sub SinglePaste_Click()
On Error GoTo InvalidBarcode
Dim EAN As Range
Sheets("Paste Here").Select
For Each EAN In ActiveSheet.Range("A:A")
Sheets("Master Stock File").Select
With Worksheets("Master Stock File")
.Range("A:A").Find(What:=EAN, After:=.Range("A1"), LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False).Activate
ActiveCell.Offset(0, 6).Select
ActiveCell.Value = ActiveCell.Value + 1
End With
If IsEmpty(EAN) Then Exit For
Next EAN
Exit Sub
InvalidBarcode:
MsgBox ("Invalid Barcode - " & "" & EAN)
End Sub
Does this make sense? Any help is greatly appreciated.
Your code uses a lot of ActiveSheet, ActiveCell, and Select that is indicative of the Macro Recorder and is generally less efficient. I'm still not sure what "the other bit" you refer to is, but here is a reworked macro: