Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel Cell Tracker

Status
Not open for further replies.

gtejas

Technical User
Oct 3, 2007
5
I needed code to track previous cell location.
It tracks previous and current cell by row and column.
If user selects a range of cell it captures the left upper cell address. I am using this do to the fact that excel does not have a keypress event for worksheet.


Global CellTracker(1, 1) As Variant 'insert in normal module

'insert the following into a worksheet module

Private Sub Worksheet_Activate()
CellTracker(0, 0) = ActiveCell.Row
CellTracker(0, 1) = ActiveCell.Column
CellTracker(1, 0) = ActiveCell.Row
CellTracker(1, 1) = ActiveCell.Column
End Sub


Private Sub Worksheet_SelectionChange(ByVal Target As Range)
CellTracker(0, 0) = CellTracker(1, 0)
CellTracker(0, 1) = CellTracker(1, 1)
CellTracker(1, 0) = Target.Row
CellTracker(1, 1) = Target.Column

msg1 = "PrviousCell = " & Cells(CellTracker(0, 0), CellTracker(0, 1)).Address
msg2 = "CurrentCell = " & Cells(CellTracker(1, 0), CellTracker(1, 1)).Address

MsgBox msg1 & vbCr & msg2
End Sub

Hope this helps some how,
gtejas
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top