How can I run VBA code saved on a workbook when one of the cells in the worksheet receives the focus?.
How can I run VBA code saved on a workbook when one of the cells in the worksheet receives the focus?.

This month, every Windows Secrets subscriber can download a one-chapter excerpt of Windows 7: The Missing Manual.Windows 7: The Missing Manual provides valuable information to help you overcome these difficulties in learning a new operating system. Subscribe today to download your free excerpt.
Check out the Workheet_SelectionChange event in the sheet module. The Target argument contains the (new) selection as a range.
This code in a worksheet object will pop a message up whenver cell A1 is selected. Range the reference as appropriate and call a routine if desired instead of popping a messagebox
Steve
<pre>Option Explicit
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
Dim rCell As Range
Set rCell = Range("a1")
If Not Intersect(Target, rCell) Is Nothing Then
MsgBox (rCell.Address & " has focus")
End If
End Sub</pre>
Thank you Gentlemen for the promptest reply.
On the same note...how can I copy the code avaiable to other cells...that is the exmaples above return the funtion result to the cell...but I'd like to have a formula on the cell so I can copy it over....Any ideas...??
Thanks agains in advance...
The code provided by Steve is very different from a formula in a cell. This is a worksheet-wide event handler; the SelectionChange event occurswhenever the user changes the selection anywhere in the worksheet, whether by using the arrow keys, keyboard shortcuts such as Ctrl+End or the mouse. You don't need to copy this to cells or something like that.
Steve's example examines whether cell A1 is part of the selection, but the event handler occurs for all cells in the worksheet. If you could explain in some detail what you would like to do, we may be able to help.