The code below is supposed to be one VBA event that is activated when 'If Not…
- User
The code below is supposed to be one VBA event that is activated when 'If Not Intersect(Target, Me.Range("E6:E305")) Is Nothing' Can the code be written so that it is more efficient and less prone to errors.
' CHANGES TO COLUMN E THAT CHANGE OR DO NOT CHANGE THE BUDGET If Target.CountLarge > 1 Then Exit Sub If Not Intersect(Target, Me.Range("E6:E305")) Is Nothing Then 'SET TRIGGER TO TRUE SO THAT IT BLOCKS SELECTION EVENT ON COLUMN E
' COST REMOVED DUE TO CANCELLATION - BUDGET NOT CHANGED Application.EnableEvents = False preventTrigger = True If Target.Value = "0" Or Target.Value = "" And Target.Offset(0, -3).Value = "Cancellation" Then Application.EnableEvents = False Me.Unprotect Password:="edit" Target.Value = "" Target.Offset(0, 4).Value = Date Me.Protect Password:="edit" MsgBox "Cost removed due to Cancellation - Budget Not Changed." & vbCrLf & "" & vbCrLf & _ "INCLUDE CANCELLATION NOTES BY DOUBLE CLICKING ON COLUMN J.", vbInformation, "CANCELLATION" Application.EnableEvents = True preventTrigger = False Exit Sub End If
'NUMBER VALUES ONLY - BUDGET NOT CHANGED Application.EnableEvents = False preventTrigger = True ' Verify that the entered value is numeric If Not IsNumeric(Target.Value) Then Application.EnableEvents = False Me.Unprotect Password:="edit" Target.Value = Target.Offset(0, 11).Value Me.Protect Password:="edit" MsgBox "Number values only - Budget Not Changed.", vbInformation, "BUDGET" Application.EnableEvents = True preventTrigger = False Exit Sub End If
'VALUE IS NIL - BUDGET NOT CHANGED Application.EnableEvents = False preventTrigger = True If Target.Value = 0# Or Target.Value = 0 Then Application.EnableEvents = False Me.Unprotect Password:="edit" Target.Value = Target.Offset(0, 11).Value Me.Protect Password:="edit" MsgBox "Value is NIL - Budget Not Changed.", vbInformation, "BUDGET" Application.EnableEvents = True preventTrigger = False Exit Sub End If
'BUDGET PREVIOUSLY ADJUSTED - BUDGET NOT CHANGED Application.EnableEvents = False preventTrigger = True If Not Target.Comment Is Nothing Then Application.EnableEvents = False Me.Unprotect Password:="edit" Target.Value = Target.Offset(0, 11).Value Me.Protect Password:="edit" MsgBox "Budget previously adjusted - Budget Not Changed.", vbInformation, "BUDGET" Application.EnableEvents = True preventTrigger = False Exit Sub End If
' NO COMPLETION DATE - BUDGET NOT ADJUSTED Application.EnableEvents = False preventTrigger = True If Target.Value <> "" And Target.Offset(0, 4).Value = "" Then Application.EnableEvents = False Me.Unprotect Password:="edit" Target.Value = Target.Offset(0, 11).Value Me.Protect Password:="edit" MsgBox "No Completion Date - Budget Not Changed.", vbInformation, "DATE" Application.EnableEvents = True preventTrigger = False Exit Sub End If
'SUB SECTOR NOT APPLICABLE BUDGET NOT CHANGED Application.EnableEvents = False preventTrigger = True If Target.Offset(0, -1).Value = "NA" Then Application.EnableEvents = False Me.Unprotect Password:="edit" Target.Value = Target.Offset(0, 11).Value Me.Protect Password:="edit" MsgBox "Sub Sector Not Applicable - Budget Not Changed.", vbInformation, "SUB SECTOR" Application.EnableEvents = True preventTrigger = False Exit Sub
- Assistant
- User
You have omitted the entire code below ' VALUE CONVERTED TO NEGATIVE - BUDGET CHANGED
- Assistant
- User
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.