Cell Change event in Excell

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • john20
    New Member
    • Jul 2008
    • 37

    Cell Change event in Excell

    Hi All,

    Is there any way so I can get event when moving cursor in excel sheet. What I meant by that if cursor is in cell A1 then I move to B1 at that time

    I want cell change event should fire. At the movement I am able to get event when you change the cell value and press enter then I can get the cell change event.

    Is there any way to achieve this. Any idea or sample code very much appriciated.

    Many Thanks

    John
  • Stewart Ross
    Recognized Expert Moderator Specialist
    • Feb 2008
    • 2545

    #2
    You can use the Worksheet SelectionChange event for this purpose. You need to place an event handling sub in the code behind the relevant worksheet. If it was sheet1 in the default workbook then you place the handler in the sheet1 code. A simple example is provided below:

    Code:
    Public Sub Worksheet_SelectionChange(ByVal target As Range)
        MsgBox "Current cell is Row " & target.Row & ", Column " & target.Column
    End Sub
    The required range parameter (called target in the example) tells you what the current range selected on the worksheet is. If you need to do different things depending on what cell is selected you can use the relevant range properties (such as .row and .column) to work out which cells you are currently on.

    If you need to respond to events on multiple worksheets you will need to have SelectionChange event handlers on the relevant code modules for each. The event handler for Sheet1 does not see or respond to the events on sheet2 if it is activated - it must have its own event handler.

    -Stewart
    Last edited by Stewart Ross; May 29 '11, 04:35 PM.

    Comment

    Working...