View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Chip Pearson Chip Pearson is offline
external usenet poster
 
Posts: 7,247
Default Macro Activation

The following Worksheet_Selection change will run the code you substitute
for the ' your code here lines whenever you exit the range named "TheRange".
It runs only when the selection move from within the range to outside of the
range. It doesn't run when you click repeated outside the range.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

Static NotInLastTime As Boolean
If Target.Cells.Count 1 Then
Exit Sub
End If

If Application.Intersect(Target, Range("TheRange")) Is Nothing Then
If NotInLastTime = False Then
'''''''''''''''''''
' your code here
'''''''''''''''''''
NotInLastTime = True
End If
Else
NotInLastTime = False
End If
End Sub


--
Cordially,
Chip Pearson
Microsoft MVP - Excel, 10 Years
Pearson Software Consulting
www.cpearson.com
(email on the web site)


"Rick B" wrote in message
...
Hi, I am relatively new to programming in Excel. Everything I know and
don't
know is a result of being self taught through reading and playing around
in
visual basic in Excel.
I am trying to make a macro run automatically in a spreadsheet when the
user
moves from a particular range of cells. I have recorded the macro as a
module. I realize that the code needs to be placed in the worksheet for
this
macro to work. I am just not exactly sure how to generate the necessary
code
to activate the macro.

My range of cells is named. When the user fills out their information
within
the named range of cells and they navigate from that range, the macro
would
initiate.

Any suggestions or help would greatly be appreciated.
--
Rick B