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?
2 Answers
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
5 Comments
Richard Lidbom
Thank you GREATLY - I will give it a try. This forum is wonderful - I have been reading and reading - couldn't find an answer.
Richard Lidbom
It works wonderfully EXCEPT the macro keeps running and running - I guess I need to clear the field after the macro is run.
ssarabando
The Worksheet_Change will run every time some value changes anywhere in the sheet. The first If makes sure that your macro will only run if there's a change in A2's content and if that value is greater than zero. So your macro shouldn't be always running (unless A2 is always changing)... Also note that clearing the field is also considered a change.
Richard Lidbom
Here is the macro I call - when this macro is through, I want to wait for the next change in A1.
ssarabando
I think you forgot to post the macro. Also, please describe what is it that you are trying to accomplish.