A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
To: Glen
Re: VBA example
On a new Excel worksheet...
Right-click the sheet tab and select "View Code" from the popup menu.
In the large white window on the right, paste in the following code:
[Code has been edited]
'---
Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo FixThings
Application.EnableEvents = False
If Target.Cells.CountLarge > 1 Then
MsgBox "One cell at a time please"
Application.EnableEvents = True
Exit Sub
Else
If Target.Address = "$B$3" Or Target.Address = "$F$3" Or Target.Address = "$J$3" Then
If Not IsNumeric(Target.Value) Then
Application.Undo
MsgBox "Numbers only"
Application.EnableEvents = True
Exit Sub
ElseIf Target.Value > 100 Then
Target.Interior.Color = vbRed
ElseIf Target.Value > 50 Then
Target.Interior.Color = vbYellow
ElseIf Target.Value > 0 Then
Target.Interior.Color = vbGreen
Else
Target.Interior.ColorIndex = xlColorIndexNone
End If
End If
End If
FixThings:
Application.EnableEvents = True
End Sub
'---
Under the File menu - click "Close and return to Microsoft Excel"
On the worksheet enter something in B3 or F3 or J3.