Richard Lidbom
Richard Lidbom

Reputation: 11

Autoexecute an Excel macro

I have a macro which is executed on the striking of ctrl-u - I would like that macro to AUTOMATICALLY execute everytime a number gt > 0 is entered into A2 is there an easy way to do that?

Upvotes: 1

Views: 1534

Answers (2)

ExcelGamesSupport
ExcelGamesSupport

Reputation: 61

An even easier solution is. Place this in the "ThisWorkBook" module

Private Sub Worksheet_Change(ByVal Target As Range)

  If Target.Address = Range("A2").Address and Target.Value >0 Then

      ' do something here
       MsgBox "This works!"

  End If
End Sub

Upvotes: 0

ssarabando
ssarabando

Reputation: 3517

You could call the macro when the cell content changes. Open Excel's the Visual Basic editor, and add something like this to the sheet where you want the macro to run automatically:

Private Sub Worksheet_Change(ByVal Target As Range)
  ' Column 1 is the A column
  If Target.Column = 1 And Target.Row = 2 Then
    If Target.Value > 0 Then
      ' call macro here
      MyMacroName
    End If
  End If
End Sub

Upvotes: 2

Related Questions