Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default Know which cell was just left

I have a sub I want to run each time a cell is changed. However, I need to
know which cell was active when the enter key is pressed. When I look at
active cell on Worksheet_Change it gives me the current cell with focus but
not the one the data was changed on.

thanks,
Jerry

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,069
Default Know which cell was just left

Here is one way...

In a general VBA module in your workbook, add a Global variable (PrevCell in
this example):
Global PrevCell As Range

In the ThisWorkbook module, add the following event code:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
'Free the object variable PrevCell
Set PrevCell = Nothing
End Sub

Private Sub Workbook_Open()
'Initialize the object variable PrevCell
Set PrevCell = ActiveCell
End Sub

Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target
As Range)
On Error Resume Next
'Do something with PrevCell
MsgBox "PrevCell was " & PrevCell.Address
'Store the activecell as PrevCell
Set PrevCell = Target
End Sub

Hope this helps,

Hutch

"JerryH" wrote:

I have a sub I want to run each time a cell is changed. However, I need to
know which cell was active when the enter key is pressed. When I look at
active cell on Worksheet_Change it gives me the current cell with focus but
not the one the data was changed on.

thanks,
Jerry

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 245
Default Know which cell was just left

Store it in a variable and update after you run your code:

Dim LastAddr
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

thisAddr = ActiveCell.Address

'your code

LastAddr = thisAddr

End Sub

--
Steve

"JerryH" wrote in message
...
I have a sub I want to run each time a cell is changed. However, I need to
know which cell was active when the enter key is pressed. When I look at
active cell on Worksheet_Change it gives me the current cell with focus
but
not the one the data was changed on.

thanks,
Jerry

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,549
Default Know which cell was just left


Target is the cell that was changed in the Worksheet_Change event.
Paste this in a sheet module and change some cells...
'--
Private Sub Worksheet_Change(ByVal Target As Range)
MsgBox Target.Address
End Sub
--
Jim Cone
Portland, Oregon USA



"JerryH"

wrote in message
I have a sub I want to run each time a cell is changed. However, I need to
know which cell was active when the enter key is pressed. When I look at
active cell on Worksheet_Change it gives me the current cell with focus but
not the one the data was changed on.
thanks,
Jerry

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,549
Default Know which cell was just left

Further...
Target can be more than one cell.
'--
Jim Cone


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Know which cell was just left

Cells(Target.Row,Target.Column)

If this post helps click Yes
---------------
Jacob Skaria


"JerryH" wrote:

I have a sub I want to run each time a cell is changed. However, I need to
know which cell was active when the enter key is pressed. When I look at
active cell on Worksheet_Change it gives me the current cell with focus but
not the one the data was changed on.

thanks,
Jerry

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default Know which cell was just left

Jim,

Your three liner works perfectly.

thanks,
Jerry

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
scroll so that the upper left cell in a range moves to the upper left of the active window Andre[_6_] Excel Programming 6 November 14th 08 09:33 PM
macro to look down cells and if negative in the right of the cell change to left of the cell [email protected][_2_] Excel Programming 9 August 7th 07 12:06 PM
How to make a cell appear in upper left (top left) corner of works jeff Excel Programming 2 March 6th 07 10:14 PM
How to point to (select) a cell to the left from a cell where I enter the = equal sign? Dmitry Excel Discussion (Misc queries) 4 June 30th 06 06:49 AM
Please help! Macro to change cell contents based on cell to the left Jennifer[_8_] Excel Programming 7 March 4th 04 01:06 AM


All times are GMT +1. The time now is 10:28 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"