Cells change based on other cell input

V

Vickie********

The code below works for what it is supposed to do. This
request is for the second portion the two need to work
together.
Here you go.
Cells F14 and F16 (first and last names)if one or both are
filled in then cells F22 and F23(X) are made red if there
isn't an X in one or the other of them. If there is then
neither are red. If only one of the F14 or F16 Cells are
filled in, then which ever isn't is turned red along with
F22 or F23 if one or the other of these cell doesn't have
an X in it. If there is and X in either F22 or F23 but
only one of the F14 or F16 cell is filled in the one with
out any input is made red.

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Target.Address = "$F$14" Or _
Target.Address = "$F$16" Then
If Target <> "" Then
Target.Interior.ColorIndex = xlNone
ElseIf Target = "" And _
UCase(Range("F22").Value) = "X" Or _
UCase(Range("F23").Value) = "X" Then
Target.Interior.ColorIndex = 3
Else
Target.Interior.ColorIndex = xlNone
End If
End If
If Target.Address = "$F$23" Or _
Target.Address = "$F$22" Then
If UCase(Target.Value) <> "X" Then
Application.EnableEvents = False
Target.ClearContents
Application.EnableEvents = True
If Range("F22") = "" And _
Range("F23") = "" Then _
Range("F14,F16").Interior.ColorIndex = xlNone
Else
If Range("F14").Value = "" Then
Range("F14").Interior.ColorIndex = 3
Else
Range("F14").Interior.ColorIndex = xlNone
End If
If Range("F16").Value = "" Then
Range("F16").Interior.ColorIndex = 3
Else
Range("F16").Interior.ColorIndex = xlNone
End If
End If
End If
End Sub
 
V

Vickie********

This is the second part of the fisrt one you guys were
helping me with. I tried the first and I think it well
work. Know I need just a little more help
 
T

Tom Ogilvy

Try this:

It colors everything red, then decides where to remove the red.

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Intersect(Range("F14,F16,F22,F23"), Target) _
Is Nothing Then Exit Sub
On Error GoTo ErrHandler
If Not Intersect(Range("F22:F23"), _
Target) Is Nothing Then
If Intersect(Range("F22:F23"), Target).Address = _
Target.Address Then
If UCase(Target.Value) <> "X" Then
Application.EnableEvents = False
Target.ClearContents
End If
End If
End If
Range("F14,F16,F22,F23").Interior.ColorIndex = 3
If Range("F14").Value <> "" Then _
Range("F14").Interior.ColorIndex = xlNone: Debug.Print 1
If Range("F16").Value <> "" Then _
Range("F16").Interior.ColorIndex = xlNone: Debug.Print 2
If Range("F14").Value <> "" And _
Range("F16").Value <> "" Then _
Range("F22:F23").Interior.ColorIndex = xlNone
If Application.CountA(Range("F22:F23")) = 0 Then _
Range("F14,F16").Interior.ColorIndex = xlNone
If Application.CountA(Range("F14,F16")) = 2 Then
If Application.CountA(Range("F22:F23")) = 1 Then _
Range("F22:F23").Interior.ColorIndex = xlNone
ElseIf Application.CountA(Range("F14,F16")) = 1 Then
If Range("F22") <> "" Then _
Range("F22").Interior.ColorIndex = xlNone
If Range("F23") <> "" Then _
Range("F23").Interior.ColorIndex = xlNone
End If
If Application.CountA(Range("F14,F16")) = 0 Then
If Range("F22") = "" Then _
Range("F22").Interior.ColorIndex = xlNone
If Range("F23") = "" Then _
Range("F23").Interior.ColorIndex = xlNone
End If
ErrHandler:
Application.EnableEvents = True
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top