Consulting

Results 1 to 8 of 8

Thread: Solved: worksheet_change event does not trigger on copy/paste

  1. #1
    VBAX Regular tools's Avatar
    Joined
    Apr 2008
    Posts
    70
    Location

    Solved: worksheet_change event does not trigger on copy/paste

    Hi all,

    when i paste some values (rows) from one excel sheet to another the worksheet_change event is not triggered properly

    Here is the code that i have written
    Is there any other event which could trigger this .?


    [vba]

    Private Sub Worksheet_Change(ByVal Target As Range)
    Sheet1.Unprotect

    On Error Resume Next
    Dim rFound As Range
    Dim rowlast
    If Not Intersect(Target, Range("D4,U4,C10:C100,E10:E100,G10:G100")) Is Nothing Then
    If Target.Column = 4 Then
    Set rFound = Sheets("TEMP").Cells.Find(What:=Target.Value, After:=Sheets("TEMP").Range("D1"), LookIn:=xlFormulas, LookAt _
    :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
    False, SearchFormat:=False)
    Target.Offset(0, 17).Value = rFound.Offset(0, 17).Value
    End If

    End If


    Sheet1.Protect


    If Sheet1.Protection.AllowInsertingRows = False Then
    Sheet1.Protect AllowInsertingRows:=True
    End If

    End Sub


    [/vba]
    Last edited by tools; 06-01-2008 at 10:52 PM.
    Regards

    If I look its because i'm

  2. #2
    VBAX Regular tools's Avatar
    Joined
    Apr 2008
    Posts
    70
    Location
    The event gets triggered and it shows the target column number as 1

    Is there a way where i can check the columns in which data has been entered
    Regards

    If I look its because i'm

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Do you mean if more than one cell changed at a time?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  4. #4
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    Perhaps at the following lines in your code (which by the way just changes a single value!),
    [VBA]
    .......Target.Offset(0, 17).Value = rFound.Offset(0, 17).Value
    MsgBox Target.Offset(0, 17).Address
    End If

    [/VBA]
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  5. #5
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    I don't think we have been supplied the whole code Bob there is a Dim which doesnt reference anything!
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  6. #6
    VBAX Regular tools's Avatar
    Joined
    Apr 2008
    Posts
    70
    Location
    Yes if more than one cell has been changed then this code does not work.
    Regards

    If I look its because i'm

  7. #7
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim rFound As Range
    Dim rowlast
    Dim cell As Range

    Sheet1.Unprotect

    On Error Resume Next
    If Not Intersect(Target, Range("D4,U4,C10:C100,E10:E100,G10:G100")) Is Nothing Then

    For Each cell In Target

    If cell.Column = 4 Then

    Set rFound = Sheets("TEMP").Cells.Find(What:=cell.Value, _
    After:=Sheets("TEMP").Range("D1"), _
    LookIn:=xlFormulas, _
    LookAt:=xlPart, _
    SearchOrder:=xlByRows, _
    SearchDirection:=xlNext, _
    MatchCase:=False, _
    SearchFormat:=False)
    cell.Offset(0, 17).Value = rFound.Offset(0, 17).Value
    End If
    Next cell
    End If

    Sheet1.Protect

    If Sheet1.Protection.AllowInsertingRows = False Then
    Sheet1.Protect AllowInsertingRows:=True
    End If

    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  8. #8
    VBAX Regular tools's Avatar
    Joined
    Apr 2008
    Posts
    70
    Location
    Thanks xld
    Regards

    If I look its because i'm

Posting Permissions

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