Results 1 to 5 of 5
  1. #1
    Silver Lounger
    Join Date
    Dec 2000
    Location
    California, USA
    Posts
    1,758
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Trigger Code By Cell Input (XP: SP3)

    Is it possible to have code run when someone inputs a value in a cell.

    As an example:
    Column E is used to enter values; not each cell in Column E will have a value entered. Therefore if someone entered a value in E5, E8 and E10 then code would be run after each value was entered.

    My guess is to use intercept but I am not sure.

    Thanks,
    John

  2. #2
    Silver Lounger
    Join Date
    Dec 2000
    Location
    California, USA
    Posts
    1,758
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Trigger Code By Cell Input (XP: SP3)

    Hans,

    I replaced the comment line with Msgbox oCell.Address

    The code worked once for the first value entered in a cell. Nothing thereafter.

    Why are you using EnableEvents = False? I thought that was reserved for bypassing the beforesave routine.

    John

  3. #3
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Re: Trigger Code By Cell Input (XP: SP3)

    EnableEvents = False is used to block any Excel Event, including opening, closing, clicking on a cell, etc.

    However, I would guess that Hans meant to set the second instance of EnableEvents = True, and that may solve your problem with no further returns.
    -John ... I float in liquid gardens
    UTC -7ąDS

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Trigger Code By Cell Input (XP: SP3)

    As JohnBF notes (thanks, John!), the second instance should be EnableEvents = True.

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Trigger Code By Cell Input (XP: SP3)

    Error corrected by HansV - thanks to JohnBF for pointing it out

    Right-click the sheet tab for the worksheet.
    Select View Code from the popup menu.
    Enter or copy the following code:

    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim oCell As Range
    If Not Intersect(Target, Range("E:E")) Is Nothing Then
    Application.EnableEvents = False
    For Each oCell In Intersect(Target, Range("E:E")).Cells
    ' Insert code to run here - oCell is the cell that has been changed.
    Next oCell
    Application.EnableEvents = True ' originally had False here
    End If
    End Sub

    You will have to replace the comment line with the code you want to run.

Posting Permissions

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