Find previous active cell

O

Otto Moehrbach

Excel XP & Win XP
Is there a way to find the previous active cell? I want to use a
Worksheet_SelectionChange event macro to fire when a selection change is
made and then I want that macro to tell me the previous active cell. My end
goal is to force a tab sequence in a group of cells even when a cell entry
is not made. Thanks for your time. Otto
 
J

Jim Thomlinson

Perhaps something like this embedded directly in the sheet...

Private Sub Worksheet_Activate()
MsgBox "Current Address " & ActiveCell.Address
MsgBox "Last address " & LastCell.Address
End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
MsgBox "Current Address " & Target.Address
MsgBox "Last address " & LastCell.Address
End Sub

Private Function LastCell() As Range
Static rngLastCell As Range

If rngLastCell Is Nothing Then Set rngLastCell = ActiveCell
Set LastCell = rngLastCell
Set rngLastCell = ActiveCell
End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top