Guest User

Untitled

a guest
Nov 18th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 KB | None | 0 0
  1. Option Explicit
  2.  
  3. Private Sub Worksheet_Change(ByVal Target As Range)
  4.  
  5. On Error GoTo ErrorHandler
  6.  
  7. Dim tbl As ListObject
  8. Dim xValue As Integer
  9. Dim KeyCells As Range
  10.  
  11. Set tbl = ActiveSheet.ListObjects("TableQuery")
  12.  
  13. On Error Resume Next
  14. If Intersect(Target, tbl.ListColumns("Qty").Range, tbl.DataBodyRange) Is Nothing Then
  15. If Intersect(Target, tbl.ListColumns("Reason delay 1").Range, tbl.DataBodyRange) Is Nothing Then
  16. If Intersect(Target, tbl.ListColumns("Reason delay 2").Range, tbl.DataBodyRange) Is Nothing Then
  17. If Intersect(Target, tbl.ListColumns("Reason delay 3").Range, tbl.DataBodyRange) Is Nothing Then Exit Sub
  18. End If
  19. End If
  20. End If
  21.  
  22. On Error GoTo 0
  23.  
  24.  
  25. If IsNumeric(Target.Value) Then
  26. If (Target.Value) < 2 Then
  27. Application.EnableEvents = False
  28. Target.Value = ""
  29. Target.Select
  30. Application.EnableEvents = True
  31. Exit Sub
  32. End If
  33. Else
  34. If (Target.Value) = "Other" Then
  35. Set KeyCells = Target.Offset(0, 1)
  36. ActiveSheet.Unprotect Password:="WowSoSecure123"
  37. KeyCells.Locked = False
  38. ActiveSheet.Protect Password:="WowSoSecure123"
  39. Exit Sub
  40. Else
  41. Exit Sub
  42. End If
  43. End If
  44.  
  45. xValue = Target.Value - 1
  46.  
  47. Set KeyCells = Intersect(Target.EntireRow, tbl.DataBodyRange)
  48.  
  49. ActiveSheet.Unprotect Password:="WowSoSecure123"
  50. Application.EnableEvents = False
  51. Target.Value = ""
  52. With KeyCells
  53. .Copy
  54. .Offset(1).Resize(xValue).Insert xlShiftDown
  55. End With
  56. ActiveSheet.Protect Password:="WowSoSecure123"
  57. Application.EnableEvents = True
  58. Application.CutCopyMode = False
  59. Target.Select
  60.  
  61. ExitHandler:
  62. ActiveSheet.Protect Password:="WowSoSecure123"
  63. Exit Sub
  64.  
  65. ErrorHandler:
  66. MsgBox Err.Description, vbOKOnly
  67. Application.EnableEvents = True
  68. Resume ExitHandler
  69.  
  70. End Sub
Add Comment
Please, Sign In to add comment