I am new to VBA and am trying to create a user-defined function in VBA that determines if there's a title and gender mismatch. E.g.: if the title is "Mr" and the gender is "F" then it'll return a Boolean of TRUE (there is a mismatch).
However, when the gender is "F" and the title is "MR", it keeps returning FALSE, as MR is a substring of MRS. Is there a way to ensure that it does an exact match?
Function GenderTitleMismatch(title As Variant, gender As Variant) As Boolean
title = UCase(trim(title))
gender = UCase(trim(gender))
If gender = "M" And UBound(Filter(Array("MR", "DR"), title)) = -1 Then
GenderTitleMismatch = True
ElseIf gender = "F" and Ubound(Filter(Array("MRS","MS","DR","MISS"), title)) = -1 Then
GenderTitleMismatch = True
Else
GenderTitleMismatch = False
End If
End Function