Excel – VB / VBA StrComp or =

excelstring-comparisonvba

What, if anything, is the benefit of using

If StrComp(strVal1, strVal2, vbTextCompare) = 0 Then

as opposed to using

If strVal1 = strVal2 Then

If Option Compare Text is set at the module level, is there any difference?

I know StrComp handles null scenarios and <> scenarios, I am only interested in the situation where strVal1 and strVal2 have non-null valid strings assigned.

Best Solution

If Option Compare Text is set at the module level, is there any difference?

No. It simply offers a finer grained control (no module-level strategy commitments). However, if you can make such a commitment, go for the x = y option: less code is always better code.