View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
zackb zackb is offline
external usenet poster
 
Posts: 18
Default Address of Cell that lost focus?

Hello there,

Here is an example of some worksheet code which could start you off ...


Option Explicit

Dim rngLast As Range

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
On Error GoTo firstRun
MsgBox "Current Address: " & Target.Address(0, 0) & vbCrLf & _
"Last Address: " & rngLast.Address(0, 0)
firstRun:
'must be last
Set rngLast = Target
End Sub


To install this code:

Copy code.
Right click sheet tab (of desired installation).
Select View Code.
Paste on right.
Alt + F8 to return to Excel.
Save before doing anything else.


Note that it will always fail out before the Range Object is set to
anything - as in the first time it is run (or the first time you select
anything/cell - you'd need to select an additional cell to get it to
trigger).


HTH, and regards,
Zack Barresse


"HotRod" wrote in message
...
I'm trying to set a default value for a column using VBA and am running
code when the Worksheet_SelectionChange is fired, the problem is that the
Target value is the Value of the cell that just got the focus, how do I
get the address of the cell that just lost focus?