+ Reply to Thread
Results 1 to 5 of 5

Worksheet Change Event Wrongly Trigger

Hybrid View

  1. #1
    Valued Forum Contributor
    Join Date
    03-28-2014
    Location
    Kuala Lumpur, Malaysia
    MS-Off Ver
    Excel 2016
    Posts
    702

    Worksheet Change Event Wrongly Trigger

    Hi,

    I am writing Worksheet Change Event to enable auto trigger to clear contents from column "SC" to "TB" if user clear contents column "B" to "I".However, there is a bit error whereby the sheet will be triggered even if user clear contents for only one column between "B" to "I"

    Before this, i have used If Range("B" & i & ":I" & i) Is Empty Then but it does not work

    For the beginner like me, I am a bit confused on the term If Not Intersect(Target, Range()) Is Nothing Then


    Here is my code.
    Private Sub Worksheet_Change(ByVal Target As Range)
    
    i = ActiveCell.Row
    
        If Not Intersect(Target, Range("B" & i & ":I" & i)) Is Nothing Then
           Range("SC" & i).Resize(1, 26).ClearContents
        End If
     
    End Sub
    Then, my next confusion is should I choose Worksheet SelectionChange or Change as both seems to have the same output
    Last edited by Faridwahidi; 12-03-2014 at 10:25 PM.

  2. #2
    Forum Expert Debraj Roy's Avatar
    Join Date
    09-27-2012
    Location
    New Delhi,India
    MS-Off Ver
    Excel 2013
    Posts
    1,469

    Re: Worksheet Change Event Wrongly Trigger

    Try This...

    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim cell As Range
    On Error GoTo Deb
    Application.EnableEvents = False
    
    For Each cell In Target
        If Target.Column >= 2 And Target.Column <= 9 And WorksheetFunction.CountBlank(Range("B" & Target.Row & ":I" & Target.Row)) = 8 Then
            Range("SC" & Target.Row).Resize(Target.Rows.Count, 26).ClearContents
        End If
    Next cell
    
    Deb:
        Application.EnableEvents = True
    End Sub
    Regards!
    =DEC2HEX(3563)

    If you like someone's answer, click the star to give them a reputation point for that answer...

  3. #3
    Valued Forum Contributor
    Join Date
    03-28-2014
    Location
    Kuala Lumpur, Malaysia
    MS-Off Ver
    Excel 2016
    Posts
    702

    Re: Worksheet Change Event Wrongly Trigger

    Hi Debraj,

    Thanks a lot


    My last question is Worksheet SelectionChange or Change seems to have the same output. what is the differences?
    Last edited by Faridwahidi; 12-03-2014 at 10:53 PM.

  4. #4
    Forum Expert Debraj Roy's Avatar
    Join Date
    09-27-2012
    Location
    New Delhi,India
    MS-Off Ver
    Excel 2013
    Posts
    1,469

    Re: Worksheet Change Event Wrongly Trigger

    Option Explicit
    
    Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Address = "$A$1" Then
        MsgBox "you have changed something... in A1"
    End If
    End Sub
    
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Target.Address <> "$A$1" Then
        MsgBox " hey.. you mave just move to another cell.. still you have not changed anything"
    End If
    End Sub
    test this one in a blank sheet..

  5. #5
    Valued Forum Contributor
    Join Date
    03-28-2014
    Location
    Kuala Lumpur, Malaysia
    MS-Off Ver
    Excel 2016
    Posts
    702

    Re: Worksheet Change Event Wrongly Trigger

    Hi Debraj,

    Many thanks for the clarification.

    Worksheet_Change will trigger on cells changes whereas SelectionChange will trigger on cells movements ..

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] VBA to trigger event change
    By jrholden in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-26-2014, 11:34 AM
  2. [SOLVED] Trigger Change Event
    By alienware in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 12-27-2012, 07:25 AM
  3. Select Box Change Event Trigger
    By excelsupportforum in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-31-2012, 12:45 PM
  4. [SOLVED] Cell value change to trigger macro (worksheet change event?)
    By Neil Goldwasser in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-10-2006, 10:00 AM
  5. [SOLVED] Worksheet Change Event-change event to trigger
    By Steph in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-18-2005, 06:05 PM

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