0

I have a range of values in a column which I am targeting.
Once any of the values in that range changes, it is supposed to call a macro. The macro I am calling works but my change event is not getting recognized. Is there something wrong with my code?

My change even macro is located on the sheet where the change event is happening:

Private Sub Worksheet_Change(ByVal Target As Range)

    If Target.Address = "$H$5:$H$32" Then
        Call SetAxes
    End If
End Sub

Do I need to be more specific with the range address?

5
  • 4
    Worksheet_calculate does not have ByVal Target As Range and you cannot just add it expecting it to work. Commented May 16, 2018 at 20:51
  • @ScottCraner Worksheet_Change didn't do anything either Commented May 16, 2018 at 20:54
  • 1
    Worksheet change does not capture changes due to formulas. You will need to save the values in another location then compare the values after calc, if different then save the new values in the other location and run the sub Commented May 16, 2018 at 20:55
  • 1
    So the question is, "Are these cells being changed by formula or by manual input directly in the cells?" Commented May 16, 2018 at 20:58
  • @ScottCraner Thanks. I changed to back to Worksheet_Calculate and simply called the macro and it works. Commented May 16, 2018 at 20:58

3 Answers 3

1

Target.Address = "$H$5:$H$32" will only be True if that entire range changes at once.

To trap changes to one or more cells within that range, use Application.Intersect like this:

If Not Application.Intersect(Target, Range("$H$5:$H$32")) Is Nothing Then
Sign up to request clarification or add additional context in comments.

Comments

0

I simply used worksheet_calculate and called the function when anything changes on the worksheet.
All the macro it is calling does is set the axes, so I don't mind if it runs repeatedly.

Private Sub Worksheet_Calculate()

        Call SetAxes

End Sub

Comments

0

as a workaround, you could add a function:

Function FakeChange() As Integer
SetAxes
FakeChange = 0
End Function

and add behind your formulas in "$H$5:$H$32" +Fakechange() like: ='your formula'+ FakeChange()

This function will be triggered when the results of your formulas are changed

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.