Stopping muliple triggers through Worksheet_Change(ByVal Target As Range)

nl05369

New Member
Joined
May 11, 2007
Messages
21
Hello expoerts,

I have a sheet whereby when 1 cell in column T is filled with a valid date, then that row in the sheet will be moved to a different sheet.
Problem is: when I perform the cut/paste, that is also seen as an alteration to the column T, starts subroutine of the cell change, and the routine fails.
How do I, if the routine for change in the date cell in column T is already active, not have it trigger again?

VBA below:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)

' This routine will move a line from active to afgewerkt if call in column U is filled with valid date.
' Otherwise, the value in the cell will be erased.

Dim Date_Check As Boolean
Dim dt As String
Dim Answer As String
Dim Changed_Cell As String

On Error GoTo MyErrorHandler:

' Set variable Changed_Cell to address of cell that
Changed_Cell = Target.Address
Cell_Value = Intersect(Target, Range("T3:T999"))
Sheets("Current").Range(Changed_Cell).Select

If Not Intersect(Target, Range("T3:T999")) Is Nothing Then GoTo Perform_Action
GoTo Skip

Perform_Action:
' Check that content of changed cell is not empty or space
If Cell_Value = "" Or Cell_Value = " " Then GoTo Skip

' Verify that entry is a valid date and nothin else.
Date_Check = IsDate(Cell_Value)

If Date_Check = "False" Then GoTo Clear_Contents   ' do nothing if the data is not a valid date
If Date_Check = "True" Then Answer = MsgBox("Do you want to move this line", vbYesNo + vbQuestion, "Move Line")
If Answer = 6 Then Call MoveLine
If Answer = 7 Then GoTo Clear_Contents

GoTo Skip


Clear_Contents:
Range(Changed_Cell).Select
ActiveCell = ""

Skip:

' to avoid the message on closing the book - "picture is too large and will be truncated", copy and paste a singe empty cell
ThisWorkbook.Worksheets(1).Cells(1, 1).Copy
ThisWorkbook.Worksheets(1).Cells(1, 1).PasteSpecial xlValues

' clear clipboard
Application.CutCopyMode = False

Exit Sub
MyErrorHandler:
If Err.Number = 1004 Then
  ActiveCell(1, -1) = "Not Found"
  'MsgBox "Not Found"
 ' ActiveCell.Offset(1, 0).Select
ElseIf Err.Number = 13 Then
'  MsgBox "You have entered an invalid value."
End If

End Sub

Sub MoveLine()
Move_Line:
    ActiveCell.Rows("1:1").EntireRow.Select
    
    Selection.Cut
    Sheets("Afgewerkt").Select
    
    ActiveCell.SpecialCells(xlLastCell).Select
    
    ActiveCell.Rows("1:1").EntireRow.Select
    Selection.Insert Shift:=xlDown
    
    ActiveSheet.Previous.Select
    
    Selection.Delete Shift:=xlUp
    
    Sheets("Current").Range("C" & (ActiveCell.Row)).Select

End Sub
 
Last edited by a moderator:

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Use:
Code:
Application.EnableEvents = False
before you make any changes in the Change event, then make sure to reset back to True when the procedure is done.
 
Upvote 0
Use:
Code:
Application.EnableEvents = False
before you make any changes in the Change event, then make sure to reset back to True when the procedure is done.

Rory... you de man!
Excelent, and simple.
Thank you very much.
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top