David Van der Vieren
David Van der Vieren

Reputation: 275

VBA If Statement in excel

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

Upvotes: 0

Views: 1971

Answers (2)

Siddharth Rout
Siddharth Rout

Reputation: 149325

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.

Upvotes: 0

David Zemens
David Zemens

Reputation: 53663

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

Upvotes: 1

Related Questions