Consulting

Results 1 to 3 of 3

Thread: Worksheet Change Event

  1. #1
    VBAX Regular
    Joined
    Jun 2005
    Location
    Sydney
    Posts
    60
    Location

    Worksheet Change Event

    I am using the Worksheet Change event to control behaviour in the sheet, but I don't want changes done via a macro to use these rules. Is there some way to exclude changes done within a macro from this code. Here is some sample code.

    [VBA]
    Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Interior.ColorIndex <> 0 Then Target.Interior.ColorIndex = 0
    End Sub

    [/VBA]

    Thanks for taking the trouble to read this.

  2. #2
    Try this

    [vba]Private Sub Worksheet_Change(ByVal Target As Range)
    Application.EnableEvents = False
    If Target.Interior.ColorIndex <> 0 Then Target.Interior.ColorIndex = 0
    Application.EnableEvents = True
    End Sub[/vba]

    Jimmy
    -------------------------------------------------
    The more details you give, the easier it is to understand your question. Don't save the effort, tell us twice rather than not at all. The amount of info you give strongly influences the quality of answer, and also how fast you get it.

  3. #3
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    This
    [vba]Application.EnableEvents = False
    'Your code
    Application.EnableEvents = True
    [/vba] has to go into all the other workbook macros as well as the Worksheet_Change one.
    Jimmy's will stop the change code looping; in the other code it will prevent the Change code from running.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

Posting Permissions

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