I've run into an issue with my Excel VBA programming. I'm pulling information from a PLC and as I get a "data transfer bit" I'm trying to save off the data and wait for another data transfer bit before saving off data again etc etc. I can easily do this with a button but this needs to be automatic. One problem that I'm running into is that I keep getting a "method range of object _worksheet failed" error whenever I try to automate this process with a cell change command. I figured a second set of eyes couldn't hurt here!
(Sequence of events: Scan two barcodes via PLC. Information is automatically updated since excel file is looking at those two PLC strings. When a transfer data bit goes high (0 to 1 (excel can see this bit go high perfectly fine)), I need to transfer the strings to a certain line and then insert another line.) - The insert and transfer of strings works perfectly fine.
Private Sub Worksheet_Change(ByVal Target As Range)
Dim KeyCells As Range
Set KeyCells = Range("P2")
Set Target = Range("P2")
If (Range("P3").Value = Range("P4").Value) Then
Range("b3:k3").Copy Range("b10:k10")
Range("C10").EntireRow.Insert
Range("B11").Formula = Range("B11").Value
Range("C11").Formula = Range("C11").Value
Range("E11").Formula = Range("E11").Value
Range("F11").Formula = Range("F11").Value
Range("G11").Formula = Range("G11").Value
Range("H11").Formula = Range("H11").Value
Range("I11").Formula = Range("I11").Value
Range("J11").Formula = Range("J11").Value
Range("K11").Formula = Range("K11").Value
End If
End Sub