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
-
Look at this thread for automatically running code when the value of a cell changes stackoverflow.com/questions/409434/…JustinJDavies– JustinJDavies2013-03-28 20:31:53 +00:00Commented 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?PowerUser– PowerUser2013-03-28 22:36:37 +00:00Commented Mar 28, 2013 at 22:36
Add a comment
|
2 Answers
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
2 Comments
David Van der Vieren
That is not working unfortunatly. the first If statement is giving me a run time error 424
David Zemens
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.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.