Forum Discussion
Need help with this work project pleaseeeee
Detect "-NO MATCH" Text in the Range
We can use the COUNTIF function to check if any cell within the range B3:HB3 contains "-NO MATCH". If any cell contains this, COUNTIF will return a number greater than 0, which we can then use in an IF statement.
Place this formula in the cell where you want the YES or NO result:
=IF(COUNTIF(B3:HB3, "*-NO MATCH*") > 0, "YES", "NO")
COUNTIF(B3:HB3, "*-NO MATCH*"): This part checks each cell in the range B3:HB3 to see if it contains "-NO MATCH". The asterisks (*) are wildcard characters that allow for partial matches, so the formula works even if "-NO MATCH" is part of a larger string.
> 0: If any cell in the range contains "-NO MATCH", COUNTIF will return a number greater than 0.
IF(..., "YES", "NO"): If the count is greater than 0, this formula will return "YES". If no cells contain "-NO MATCH", it will return "NO".
This formula only detects "-NO MATCH" and cannot detect cell color. Excel functions cannot directly check for conditional formatting or cell color.
If you need to detect cell color, it would require VBA (macros) because regular Excel functions don’t have access to cell formatting properties like color.
VBA macro that checks each cell in the specified range (B3:HB3) for either the "-NO MATCH" text or a red fill color (based on your conditional formatting). If it finds any cell that meets these conditions, it will set the result cell to "YES". Otherwise, it will set it to "NO"
Function CheckForError(rng As Range) As String
Dim cell As Range
Dim hasError As Boolean
hasError = False
' Loop through each cell in the range
For Each cell In rng
' Check if the cell contains "-NO MATCH"
If InStr(1, cell.Value, "-NO MATCH", vbTextCompare) > 0 Then
hasError = True
Exit For
End If
' Check if the cell's fill color is red
If cell.Interior.Color = RGB(255, 0, 0) Then
hasError = True
Exit For
End If
Next cell
' Return "YES" if there's an error, "NO" otherwise
If hasError Then
CheckForError = "YES"
Else
CheckForError = "NO"
End If
End Function
In the cell where you want the result (YES or NO), enter this formula:
=CheckForError(B3:HB3)