Home » excel » excel – vba worksheet_change for pasting value from one sheet to another is not working, but works manually

excel – vba worksheet_change for pasting value from one sheet to another is not working, but works manually

Posted by: admin April 23, 2020 Leave a comment

Questions:
Private Sub Worksheet_Change(ByVal target As Range)

    If Intersect(target, Worksheets("SheetA").Range("V:V")) Is Nothing Then 
        Application.EnableEvents = False
        thisrow = target.Row
        Worksheets("SheetB").Cells(12, 1).Value = Worksheets("SheetA").Range("A" & thisrow).Value
    End If

    Application.EnableEvents = True
End Sub

I am trying to populate SheetB’s cell A12 under the condition that SheetA’s Column V was triggered, and the value I am assigning SheetB A12 is the A&the row of the trigger.

However, I can’t seem to get the code to work.

If someone can point out what’s wrong with the code that would be great!
And I was wondering if anyone has tips on debugging subs like Workbook_SheetChange/ worksheet_change

Edit:

I posted my new code, instead of using workbook_sheetchange, I am trying worksheet_change.

It is still not working, however, when I run it manually it does work. And in the immediate window, I type “? Application.EnableEvents = True” and it returns true.

How to&Answers:

This works for me. This goes in SheetA.

Private Sub Worksheet_Change(ByVal Target As Range)

If Not Intersect(Target, WorkSheets("A").Range("V:V")) Is Nothing Then

    'Application.EnableEvents = False

    thisrow = Target.Row
    Debug.Print thisrow

    WorkSheets("B").Cells(12, 1).Value = WorkSheets("A").Cells(thisrow, 1).Value

    'Application.EnableEvents = True

End If

End Sub

Edit: per vacip’s comment.