vAs the title suggests, I'm trying to copy and paste values to keep as a log as these values will be deleted shortly after they've been entered.
Long story short, a user will scan a barcode and a unique string of characters that correspond to the scanned barcode will be automatically entered into whichever cell is selected (usually A2). These strings are parent barcodes, so immediately after one has been scanned into A2 the user will start scanning their related children barcodes into B2, B3 and so on depending on how many children there are (always a completely random number).
Here's what I have so far:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim ws As Worksheet
Dim intRow As Integer
Dim intCount As Integer
Set ws = Worksheets("log")
intRow = ws.Range("A1").CurrentRegion.Rows.Count + 1
'Check if WandID exist in log.
If Target.Address = "$A$2" Then
intCount = Application.WorksheetFunction.CountIf(ws.Range("D:D"), Target.Value)
If intCount <> 0 Then
Target.Interior.Color = RGB(255, 0, 0)
MsgBox "this wandID has already been used, please try a different barcode"
Range("A2").ClearContents
End
Else
Target.Interior.Color = xlNone
ws.Cells(intRow, "D") = Target.Parent.Range("A2")
ws.Cells(intRow, "E") = Target
End If
End If
End Sub
On the destination worksheet (named 'log') I've set up a simple table to organise the copied / scanned data and added some dummy data as a first entry - seeing as this workbook will be used regularly I wanted this process to keep adding scanned codes beneath the previous (dummy parent code in D2, dummy child codes in E2:E9), so ideally when I enter a new parent code into A2 of the source sheet, it should be copied to D10 on the destination sheet, and any corresponding child codes added to B2 etc. of the source sheet should be copied to E10 etc. of the destination sheet. Instead what's happening is the parent code will be added to D10:E10.
I have a feeling the line
"ws.Cells(intRow, "E") = Target"
is the problem, but not sure of what to change it to. Any help or advice would be hugely appreciated!