Last ActiveCell

S

Steven

When you change cells is there a way to tell which was the last active cell.

Thank you,

Steven
 
F

FSt1

hi
excel doesn't remember last cells but you can do it with variables.
dim r as range
range("A1").select
set r = activecell
range("B9").select 'A1 was last activecell
set r = activecell 'now B9 is last activecell.

you can set varaibles for last sheet also so as to return to a point(sheet
and cell) after going off to do other stuff.

regards
FSt1

regards
FSt1
 
K

Kent Prokopy

Put this in the ThisWorkBook module:

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
Dim LastCell As String
LastCell = Cells(Target.Row, Target.Column).Address
End Sub
 
O

Otto Moehrbach

Bob
Is there some reference that has to be active for this Ctrl-Z to work?
I have 2002 and Ctrl-Z doesn't do anything for me. Thanks for your time.
Otto
 
J

Jim Rech

Ctrl-z is Undo.

--
Jim
| Bob
| Is there some reference that has to be active for this Ctrl-Z to work?
| I have 2002 and Ctrl-Z doesn't do anything for me. Thanks for your time.
| Otto
| | > Ctrl-Z will take you back there.
| >
| > --
| > __________________________________
| > HTH
| >
| > Bob
| >
| > | >> When you change cells is there a way to tell which was the last active
| >> cell.
| >>
| >> Thank you,
| >>
| >> Steven
| >
| >
|
 
O

Otto Moehrbach

Jim
Maybe I just missed something, but the OP was asking how to find the
previously selected cell, and a selection change does not get into the Undo
buffer. Hitting Undo will take him back to the previous cell only if he
changed the contents of that cell. What did I miss? Otto
 
J

Jim Rech

You interpreted his "last activecell" as "previously selected cell". Just
as valid is the last active cell in the sheet (gotten to via {End}{Home}).
However I was just saying what Ctrl-z was since I thought you were asking.
I have no opinion on the efficacy of Bob's suggestion<g>.

--
Jim
| Jim
| Maybe I just missed something, but the OP was asking how to find the
| previously selected cell, and a selection change does not get into the
Undo
| buffer. Hitting Undo will take him back to the previous cell only if he
| changed the contents of that cell. What did I miss? Otto
| | > Ctrl-z is Undo.
| >
| > --
| > Jim
| > | > | Bob
| > | Is there some reference that has to be active for this Ctrl-Z to
| > work?
| > | I have 2002 and Ctrl-Z doesn't do anything for me. Thanks for your
| > time.
| > | Otto
| > | | > | > Ctrl-Z will take you back there.
| > | >
| > | > --
| > | > __________________________________
| > | > HTH
| > | >
| > | > Bob
| > | >
| > | > | > | >> When you change cells is there a way to tell which was the last
| > active
| > | >> cell.
| > | >>
| > | >> Thank you,
| > | >>
| > | >> Steven
| > | >
| > | >
| > |
| >
|
 
B

BillCPA

Not sure who Otto and Jim are or why they are so combative.

I was looking for the same thing today and came across your question.
Kent's idea is pretty close, and I worked from that. Here is what I ended up
with.

Define a couple of Public strings: ThisCell and LastCell. Then in your
Sheet Module, put this:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

LastCell = ThisCell
ThisCell = ActiveCell.Address

End Sub

You may also want to initialize ThisCell in the Workbook_Open module.

Then each time you move to a different cell, LastCell will give you the cell
address of the previous cell.
 

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