View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
Jim Thomlinson[_4_] Jim Thomlinson[_4_] is offline
external usenet poster
 
Posts: 1,119
Default Run macro but let user update spreadsheet while it runs

There is an on chnge event that will fire each time a cell is changed. You
can capture this event and run your macro based on what was changes to what
in which cell

In the VB editor double click the sheet you want to add the code to (in the
project explorer). There is a drop down at the top left of the code window
indicating general. Change it to Worksheet. Doing this will add a selection
change sub to your procedure which you can just delete. In the drop down to
the right of that you can select which event you want. Choose Change. You
will get code similar to this

Private Sub Worksheet_Change(ByVal Target As Range)
MsgBox Target.Address & vbTab & Target.Value
End Sub

I have added a message box showing what was changed and where. There is no
keypress event on a sheet.
--
HTH...

Jim Thomlinson


"Ev" wrote:

Yes. But I'd like to avoid stopping and restarting the macro.

In Pascal I believe there was a "keypressed" command (boolean). Using this
command you could check to see if a key was pressed by the user while the
program was running in a loop. If so, it allowed the program to go to the
buffer and get that key. Then based on what key was pressed, the program
could branch to code that performed the action the user wanted.

To put that into practical terms for my spreadsheet, I'd like the user to
simply press the "H" key if he wants to change heading or the "S" key to
change speed.

"Ev" wrote:

How can I run an Excel macro but let the user update the spreadsheet while
the macro is running?