Cells or Range ? LostFocus

  • Thread starter Thread starter LRay67
  • Start date Start date
L

LRay67

Can cells or ranges have a LostFocus function behind it? If not LostFocus is
there something that is compatible with this function for Cells or Ranges?

Thanks

Linda
 
Hi Linda,

To my understanding 'Worksheet_SelectionChange' or
'Workbook_SheetSelectionChange' are about as close as it gets, but
'Target' will be the cell / range you are moving to not the one you
have left.

Cheers,
Ivan.
 
Hi again,

There are probably other ways to do this (usually are), but you could
try defining a global variable and keeping that up to date with the
active range / cell. Here's an example which you would pop in the
ThisWorkbook module or a sheet module with the correct modifications:

Private ExitRng As Range, ExitCell As Range

Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal
Target As Range)
Dim a As String
If Not ExitRng Is Nothing Then
msg = "You just left range " & ExitRng.Address
msg = msg & " that had cell " & ExitCell.Address & " active"
msg = msg & vbCr & " and you have gone to " & Target.Address
msg = msg & " with the active cell being " &
ActiveCell.Address
MsgBox msg
End If
Set ExitRng = Target
Set ExitCell = ActiveCell
End Sub

Cheers,
Ivan.
 
Back
Top