How to invoke a macro automatically

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

This is probably the stupidest question today; however, I don't know the answer. I have used Access and have done a lot of VBA programming with it. When I want to do something with programing, I write code to execute when something happens - usually in my form. In excel, I'm having a problem understanding how to invoke a macro based on some other event on the spreadsheet. My question is this. If I enter a number in cell A1 and then hit the enter button, what code would cause the cursor to go to cell D2? If I can see this, then I can hopefully figure out how to invoke other macros based on hitting the enter key. Thanks in advance. The only stupid question is one not asked..

Don Rountree
 
Hi Don
in your case I'd use the 'Selection_change' event. Put the following
code in your worksheet module:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Cells.count > 1 Then Exit Sub
If Not Intersect(Target, Range("A1")) Is Nothing Then exit sub
range("D2").select
End Sub

for more information about event procedures see
http://www.cpearson.com/excel/events.htm
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top