'Change Background when formula removed by user change
Aim:
Change background colour if there is no formula (when user overrides defaults formula goes and this needs to be highlighted)
Private Sub Worksheet_Change(ByVal Target As Range)
Set currentsheet = ActiveWorkbook.Sheets("Audit Findings")
'#############
'CHECK IF ANY MISSING FORMULAS WHERE NOT ALLOWED
Dim rng As Range
Dim row As Range
Dim cell As Range
Set rng = currentsheetRange("J7:J11")
For Each cell In rng
If cell.HasFormula Then
Range(cell.Address).Interior.ColorIndex = 37
' MsgBox "Cell " & cell.Address & " contains a formula."
Else
Range(cell.Address).Interior.Color = RGB(255, 0, 0)
'MsgBox "The cell has no formula."
End If
Next cell
'#############
'CHECK IF ANY BLANKS WHERE NOT ALLOWED
On Error GoTo Whoa
Application.EnableEvents = False
'Set range to check
If Not Intersect(Target, Range("E7:J11")) Is Nothing Then
'check length and reverse if blank as has to be a value
'#################
If Len(Trim(Target.Value)) = 0 Then Application.Undo
End If
LetsContinue:
Application.EnableEvents = True
Exit Sub
Whoa:
MsgBox Err.Description
Resume LetsContinue
End Sub
References:
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
