title: VBA run macro on cell change?
body: <p>I have the following code and function that is supposed to run when the user types/pastes into a cell.</p>
  
  <pre><code>'Insert Depot Memo Data for user
   Dim oCell As Range, targetCell As Range
      Dim ws2 As Worksheet
      On Error GoTo Message
      If Not Intersect(Target, Range("C:C")) Is Nothing Then ' &lt;-- run this code only if a value in column I has changed
          If Not GetWb("Depot Memo", ws2) Then Exit Sub
  
          With ws2
              For Each targetCell In Target
                  Set oCell = .Range("J1", .Cells(.Rows.Count, "J").End(xlUp)).Find(what:=targetCell.Value, LookIn:=xlValues, lookat:=xlWhole)
                  If Not oCell Is Nothing Then
                      Application.EnableEvents = False
                      targetCell.Offset(0, 1).Value = oCell.Offset(0, 1)
                       targetCell.Offset(0, 2).Value = oCell.Offset(0, -2)
  
                      Application.EnableEvents = True
                  End If
              Next
          End With
      End If
  </code></pre>
  
  <p>Function:</p>
  
  <pre><code>Function GetWb(wbNameLike As String, ws As Worksheet) As Boolean
      Dim Wb As Workbook
      For Each Wb In Workbooks
          If Wb.Name Like "*" &amp; wbNameLike &amp; "*" Then '&lt;-- check if workbook name contains "Depot Memo"
              Set ws = Wb.Worksheets(1)
              Exit For
          End If
      Next
      GetWb = Not ws Is Nothing
  End Function
  </code></pre>
  
  <p>This code works, but it is not launching correctly. As soon as the user types/pastes a value into the cell (once the cell has changed) the code is supposed to run.</p>
  
  <p>At the moment, the code is not working unless the user escapes the cell and then goes back to click on it.</p>
  
  <p>I have this code under a private worksheet selection change event. I don't know if this is right? When i try to put it under a private worksheet change event it doesn't do anything.</p>
  
  <p>Please can someone show me where i am going wrong?</p>