I wrote the code making the warning disappear while the user is entering
something in C21 on purpose. The problem as I saw it was, if the warning
were allowed to remain during editing, there would be no practical way to
protect if from being modified (either on purpose or by accident). Consider
if the user accidentally deleted the closing parenthesis from the warning
message (although any deletion and/or modification will have the same
effect, I just chose the smallest one)... then the program would not be able
to recognize it as the warning message any more and would treat it as newly
edited text. That means when the user leaves the cell, a new warning message
would be added to the remaining text in the cell (the user's new text plus
the remainder of the modified warning message). To protect the warning
message against this scenario, I decided to remove it when the user went to
edit the text in C21 and restore it when they were finished. If you really
do not like this action, I can modify the code to leave the warning message
in the cell during editing... just let me know. Meanwhile, here is the code
to place the warning message in front of the user's entry...
'********** START OF CODE **********
Const Warning As String = "(Construction material may contain lead.) "
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$C$17" Or Target.Address = "$C$21" Then
Application.EnableEvents = False
Range("C21").Value = Replace(Range("C21").Value, Warning, "")
If Range("C17").Value < 1980 Then
Range("C21").Value = Warning & Range("C21").Value
End If
Application.EnableEvents = True
End If
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim Value
If Target.Address = "$C$21" Then
Application.EnableEvents = False
Range("C21").Value = Replace(Range("C21").Value, Warning, "")
Application.EnableEvents = True
Else
If Range("C17").Value < 1980 And _
InStr(Range("C21").Value, Warning) = 0 Then
Application.EnableEvents = False
Range("C21").Value = Warning & Range("C21").Value
Application.EnableEvents = True
End If
End If
End Sub
'********** END OF CODE **********
Rick