Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. Private Sub Worksheet_Change(ByVal Target As Range)
  2. Dim rngToCheck As Range
  3. Dim NumA As Variant, NumB As Variant
  4. Dim i As Long
  5.  
  6. On Error GoTo Whoa
  7.  
  8. '~~> Set the relevant range
  9. Set rngToCheck = Union(Range("G12:G42"), Range("J12:J42"))
  10.  
  11. Application.EnableEvents = False
  12.  
  13. If Not Intersect(Target, rngToCheck) Is Nothing Then
  14. For i = 12 To 42 Step 2 '<~~ Loop through only even rows
  15. NumA = Range("G" & i).Value
  16. NumB = Range("J" & i).Value
  17.  
  18. If IsNumeric(NumA) And IsNumeric(NumB) And NumB <> 0 Then
  19. If ((NumB - NumA) / NumA) * 100 < 50 Then
  20. MsgBox "The Glass U-value and Total System U-value appear very similar. Please check the input values for accuracy!"
  21. Exit For
  22. End If
  23. End If
  24. Next i
  25. End If
  26.  
  27. Letscontinue:
  28. Application.EnableEvents = True
  29. Exit Sub
  30. Whoa:
  31. MsgBox Err.Description
  32. Resume Letscontinue
  33. End Sub
  34.  
  35. Private Sub Worksheet_Change(ByVal Target As Range)
  36. If Target.Value = vbNullString Then Exit Sub
  37. Dim cell As Range
  38.  
  39. On Error GoTo ws_exit
  40.  
  41. Application.EnableEvents = False
  42.  
  43. With Target
  44.  
  45. If .Column = 3 Then
  46.  
  47. With .EntireColumn
  48.  
  49. Set cell = .Find(What:=Target.Value, AFter:=.Cells(1, 1))
  50. If cell.Address = Target.Address Then
  51.  
  52. Set cell = .FindNext()
  53. End If
  54.  
  55. If Not cell.Address = Target.Address Then
  56.  
  57. MsgBox "This Glazing Reference already exists. Please ensure you have a unique reference identifier less than 20 characters in length", vbOKOnly
  58. End If
  59. End With
  60. End If
  61. End With
  62.  
  63. ws_exit:
  64. Application.EnableEvents = True
  65. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement