0

I want to capture when value changes in the cell A2

I tried the below code but it is not working

Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Target, Me.Range("H5")) Is Nothing Then Macro
End Sub

I have a breakpoint inside the macro but its not coming till there I also tried the below, but no luck

Private Sub Worksheet_Change(ByVal Target As Range)
    MsgBox (Target.Column)
End Sub

2 Answers 2

1

Worksheet_Change takes a single parameter Target of type Range. To check if you have changed the range you are interested in you can compare the target to that range, in your case:

If Target = Range("A2") Then
    'Do something
End If

This lets you compare a Range object with another Range object with minimal fuss.

And also put it in the correct sheet.... :P

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

Comments

0

I found out the reason

I placed the macro in wrong place i.e in a different module

For the Private Sub Worksheet_Change to work, we need to place it in the sheet which needs that detection I followed the below steps

  1. We need to go to Excel VBA editor by pressing ALT + F11
  2. Double click on sheet which contains our target cell e.g. Sheet1
  3. Add the below code to the sheet

Comments

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.