开发者

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?


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


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜