1

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 2

2

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
Sign up to request clarification or add additional context in comments.

5 Comments

Thank you GREATLY - I will give it a try. This forum is wonderful - I have been reading and reading - couldn't find an answer.
It works wonderfully EXCEPT the macro keeps running and running - I guess I need to clear the field after the macro is run.
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.
Here is the macro I call - when this macro is through, I want to wait for the next change in A1.
I think you forgot to post the macro. Also, please describe what is it that you are trying to accomplish.
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.