The code must be placed in the VBA for the sheet in question. If this is not running at all (which I'm guessing it's not as you haven't mentioned the errors) then you must have put it in
- the wrong worksheet, or
- the VBA sheet for ThisWorkBook, or
- a VBA module
When you put it in the right place and enter some data on the sheet you will immediately get an Error 13 Type Mismatch on this line
If Range("A:C") = "Waiting" And "Complete" Then
The reason for that is because
"Complete"
is not a Boolean expression. It should be
If Range("A1") = "Waiting" And Range("B1") = "Waiting" And Range("C1") = "Complete" Then
The next problem is that this routine only ever looks at Row 1 on the WorkSheet. You should use
Target
to determine the range for the Font. This works
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rwRange As String
rwRange = "A" + CStr(Target.Row) + ":C" + CStr(Target.Row)
Dim r As Range
Set r = Range(rwRange)
With r.Font
If r.Cells(1, 1) = "Waiting" And r.Cells(1, 2) = "Waiting" And r.Cells(1, 3) = "Complete" Then
.Strikethrough = True
.Color = 255
Else
.Strikethrough = False
.ColorIndex = xlAutomatic
End If
End With
End Sub
[EDIT]
See the comment from @Dave-Kreskowiak in his solution...
Quote:
Perhaps a better solution would be to conditional formatting?
I think he is spot-on ...
- it will perform better
- if that was the only bit of VBA in your worksheet then removing it will improve the size on disk of the workbook
- No issues if Users turn off macros
If you do go down that route then
- highlight columns A through C,
- select Conditional Formatting,
- New Rule
- "Use a formula to determine which cells to format"
- Enter this formula
=AND(AND($A1="Waiting", $B1="Waiting"),$C1="Complete")
- Click Format
- Choose Font Color and Strikethrough
- Hit "Ok" through the dialogs until complete