0

He all I need help writing an If statement that will run a macro every time the value in cell D8 is over one. No idea where to start

2
  • Look at this thread for automatically running code when the value of a cell changes stackoverflow.com/questions/409434/… Commented Mar 28, 2013 at 20:31
  • Are you sure you need a macro? What do you need it to do if your trigger cell is > 1? Commented Mar 28, 2013 at 22:36

2 Answers 2

1

Here you go...

Private Sub Worksheet_Change(ByVal Target As Range)

If Intersect(Target, Range("D1")) Is Nothing Then Exit Sub
If Not Range("D1").Value > 1 Then Exit Sub

MsgBox "D1 > 0"

End Sub

For more info on the _Change event:

http://msdn.microsoft.com/en-us/library/office/ff839775.aspx

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

2 Comments

That is not working unfortunatly. the first If statement is giving me a run time error 424
1: Check for typos. 2. Make sure you have put this in the Worksheet's code module, NOT in an ordinary code module. 3. If you still can't get it to work, debug the value of Target.
0

It is a simple if statement.

    If Range("D8").Value > 1 Then
        '~~> Your code here
    End If

You can put that in the Worksheet_Change event. I would also recommend reading this link which talks about Worksheet_Change

If the value in Range("D8") is changing because of a formula then you might have to use the _Calculate event. See this link for an example.

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.