+ Reply to Thread
Results 1 to 8 of 8

Worksheet Change event

  1. #1
    DoctorG
    Guest

    Worksheet Change event

    I want to execute a specific routine whenever a cell of a certain column
    changes.

    All is OK if I press enter and the cursor is programmed to stay in the cell.
    Then I check the ActiveCell.Column property and execute the code. I have a
    problem if the user leaves the cell i.e. with a right or left arrow and the
    active column upon execution of the Worksheet Change routine is different to
    the one I wish to monitor.

    Is there a way to know the address of the cell that triggered the Change
    Event instead of the current/active cell ?

  2. #2
    DoctorG
    Guest

    RE: Worksheet Change event

    Sorry for posting this in the General section instead of the Programming
    one....

  3. #3
    Dave Peterson
    Guest

    Re: Worksheet Change event

    You could use the Worksheet_change event and Target.

    Target will tell you what cell was just changed by the user:

    Option Explicit
    Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Cells.Count > 1 Then Exit Sub
    If Intersect(Target, Me.Range("a1:a100")) Is Nothing Then Exit Sub

    Msgbox "User changed: " & target.address

    End Sub

    If you want to read more about these kinds of events:

    Chip Pearson's site:
    http://www.cpearson.com/excel/events.htm

    David McRitchie's site:
    http://www.mvps.org/dmcritchie/excel/event.htm

    DoctorG wrote:
    >
    > I want to execute a specific routine whenever a cell of a certain column
    > changes.
    >
    > All is OK if I press enter and the cursor is programmed to stay in the cell.
    > Then I check the ActiveCell.Column property and execute the code. I have a
    > problem if the user leaves the cell i.e. with a right or left arrow and the
    > active column upon execution of the Worksheet Change routine is different to
    > the one I wish to monitor.
    >
    > Is there a way to know the address of the cell that triggered the Change
    > Event instead of the current/active cell ?


    --

    Dave Peterson

  4. #4
    Bob Phillips
    Guest

    Re: Worksheet Change event

    Use Target.column, not activecell. I assume that you are using the worksheet
    change event.

    --

    HTH

    Bob Phillips

    (remove nothere from the email address if mailing direct)

    "DoctorG" <DoctorG@discussions.microsoft.com> wrote in message
    news:94F58163-BB05-4CCB-B3F6-090F2A2B2313@microsoft.com...
    > I want to execute a specific routine whenever a cell of a certain column
    > changes.
    >
    > All is OK if I press enter and the cursor is programmed to stay in the

    cell.
    > Then I check the ActiveCell.Column property and execute the code. I have a
    > problem if the user leaves the cell i.e. with a right or left arrow and

    the
    > active column upon execution of the Worksheet Change routine is different

    to
    > the one I wish to monitor.
    >
    > Is there a way to know the address of the cell that triggered the Change
    > Event instead of the current/active cell ?




  5. #5
    DoctorG
    Guest

    RE: Worksheet Change event

    Sorry for posting this in the General section instead of the Programming
    one....

  6. #6
    Dave Peterson
    Guest

    Re: Worksheet Change event

    You could use the Worksheet_change event and Target.

    Target will tell you what cell was just changed by the user:

    Option Explicit
    Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Cells.Count > 1 Then Exit Sub
    If Intersect(Target, Me.Range("a1:a100")) Is Nothing Then Exit Sub

    Msgbox "User changed: " & target.address

    End Sub

    If you want to read more about these kinds of events:

    Chip Pearson's site:
    http://www.cpearson.com/excel/events.htm

    David McRitchie's site:
    http://www.mvps.org/dmcritchie/excel/event.htm

    DoctorG wrote:
    >
    > I want to execute a specific routine whenever a cell of a certain column
    > changes.
    >
    > All is OK if I press enter and the cursor is programmed to stay in the cell.
    > Then I check the ActiveCell.Column property and execute the code. I have a
    > problem if the user leaves the cell i.e. with a right or left arrow and the
    > active column upon execution of the Worksheet Change routine is different to
    > the one I wish to monitor.
    >
    > Is there a way to know the address of the cell that triggered the Change
    > Event instead of the current/active cell ?


    --

    Dave Peterson

  7. #7
    Bob Phillips
    Guest

    Re: Worksheet Change event

    Use Target.column, not activecell. I assume that you are using the worksheet
    change event.

    --

    HTH

    Bob Phillips

    (remove nothere from the email address if mailing direct)

    "DoctorG" <DoctorG@discussions.microsoft.com> wrote in message
    news:94F58163-BB05-4CCB-B3F6-090F2A2B2313@microsoft.com...
    > I want to execute a specific routine whenever a cell of a certain column
    > changes.
    >
    > All is OK if I press enter and the cursor is programmed to stay in the

    cell.
    > Then I check the ActiveCell.Column property and execute the code. I have a
    > problem if the user leaves the cell i.e. with a right or left arrow and

    the
    > active column upon execution of the Worksheet Change routine is different

    to
    > the one I wish to monitor.
    >
    > Is there a way to know the address of the cell that triggered the Change
    > Event instead of the current/active cell ?




  8. #8
    DoctorG
    Guest

    RE: Worksheet Change event

    Thank you both!! You 've been most helpful.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1