Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Option Explicit
- Private Sub Worksheet_Change(ByVal Target As Range)
- On Error GoTo ErrorHandler
- Dim tbl As ListObject
- Dim xValue As Integer
- Dim KeyCells As Range
- Set tbl = ActiveSheet.ListObjects("TableQuery")
- On Error Resume Next
- If Intersect(Target, tbl.ListColumns("Qty").Range, tbl.DataBodyRange) Is Nothing Then
- If Intersect(Target, tbl.ListColumns("Reason delay 1").Range, tbl.DataBodyRange) Is Nothing Then
- If Intersect(Target, tbl.ListColumns("Reason delay 2").Range, tbl.DataBodyRange) Is Nothing Then
- If Intersect(Target, tbl.ListColumns("Reason delay 3").Range, tbl.DataBodyRange) Is Nothing Then Exit Sub
- End If
- End If
- End If
- On Error GoTo 0
- If IsNumeric(Target.Value) Then
- If (Target.Value) < 2 Then
- Application.EnableEvents = False
- Target.Value = ""
- Target.Select
- Application.EnableEvents = True
- Exit Sub
- End If
- Else
- If (Target.Value) = "Other" Then
- Set KeyCells = Target.Offset(0, 1)
- ActiveSheet.Unprotect Password:="WowSoSecure123"
- KeyCells.Locked = False
- ActiveSheet.Protect Password:="WowSoSecure123"
- Exit Sub
- Else
- Exit Sub
- End If
- End If
- xValue = Target.Value - 1
- Set KeyCells = Intersect(Target.EntireRow, tbl.DataBodyRange)
- ActiveSheet.Unprotect Password:="WowSoSecure123"
- Application.EnableEvents = False
- Target.Value = ""
- With KeyCells
- .Copy
- .Offset(1).Resize(xValue).Insert xlShiftDown
- End With
- ActiveSheet.Protect Password:="WowSoSecure123"
- Application.EnableEvents = True
- Application.CutCopyMode = False
- Target.Select
- ExitHandler:
- ActiveSheet.Protect Password:="WowSoSecure123"
- Exit Sub
- ErrorHandler:
- MsgBox Err.Description, vbOKOnly
- Application.EnableEvents = True
- Resume ExitHandler
- End Sub
Add Comment
Please, Sign In to add comment