0

Hi I'm new to VBA so apologies if this is a really simple fix.

The following code keeps returning Excel Error '91': object variable or with block variable not set.

Private Sub Worksheet_Change(ByVal Target As Range)

 If Intersect(Target, Range("$B$7")) = Worksheets("Team Amendment Tables").Range("$C$7") Then
 Application.Run "TargetUpdate1"

End If

End Sub

Any thoughts on how to resolve this? Context: Drop Down List in Sheet 7 to trigger Macro: TargetUpdate1 Once without loop.

1 Answer 1

2

Your Intersect will return Nothing if any cell other than B7 is changed, so test for that first:

Private Sub Worksheet_Change(ByVal Target As Range)

    If Not Intersect(Target, Range("$B$7")) Is Nothing Then
        If Range("$B$7").Value = Worksheets("Sheet1").Range("$C$7").Value Then
            Application.Run "TargetUpdate1"
        End If
    End If

End Sub
Sign up to request clarification or add additional context in comments.

1 Comment

Absolute Legend. Thanks for your help!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.