This module compares columns "S"&"Q" and "Z"&"I" against each other. I am not sure why it works like this; however, this code produces the enrll_Mismatch_Msg only when they match at the moment. I managed to write a short snippet which fixes this; however, it seems to be unreliable. I'm looking for code that can compare two columns against another two columns and produce a message in a fifth column.
Code:
Sub Cost_Match(ws2) 'refers to a worksheet
Dim My_Rows As Integer, My_New_Rows As Integer
Dim My_Text As String, my_text_2 As String
Dim My_Found_B As Integer
Dim Not_Found
Dim enrll_Mismatch_Msg As String
enrll_Mismatch_Msg = "."
For My_Rows = 4 To Range("S" & Rows.Count).End(xlUp).Row
My_Text = Range("S" & My_Rows).Value & Range("Q" & My_Rows).Value
For My_New_Rows = 4 To Range("Z" & Rows.Count).End(xlUp).Row
my_text_2 = Range("Z" & My_New_Rows).Value & Range("I" & My_New_Rows).Value
If My_Text = my_text_2 Then
My_Found_B = My_Found_B + 1
If My_Found_B = 1 Then
Range("W" & My_Rows) = enrll_Mismatch_Msg
Else
Range("W" & My_Rows) = enrll_Mismatch_Msg
End If
End If
Next My_New_Rows
Next My_Rows
Call Cost_Matching_Fix(ws2)
End Sub
Sub Cost_Matching_Fix(ws2)
Dim i As Integer
With ws2
For i = 4 To Range("S" & Rows.Count).End(xlUp).Row
If Range("W" & i).Value = "." Then
Range("X" & i).ClearContents
Else
If Not IsEmpty(Range("T" & i)) Then
Range("X" & i).ClearContents
Else
Range("X" & i) = "Cost Mismatch"
End If
End If
Next i
End With
End Sub