📊 VBA (Excel)
Color Code Negative Numbers
Colors negative numeric values red across the current selection, positive values left unchanged.
ColorCodeNegativeNumbers.bas
Attribute VB_Name = "ColorCodeNegativeNumbers"
Option Explicit
Public Sub ColorCodeNegativeNumbers()
Dim cell As Range
Dim count As Long
count = 0
For Each cell In Selection
If IsNumeric(cell.Value) And cell.Value <> "" Then
If cell.Value < 0 Then
cell.Font.Color = RGB(192, 0, 0)
count = count + 1
Else
cell.Font.ColorIndex = xlColorIndexAutomatic
End If
End If
Next cell
MsgBox count & " negative value(s) colored red.", vbInformation
End Sub