Help with if statement

  • Thread starter Thread starter Ayo
  • Start date Start date
A

Ayo

if c1="INDIANAPOLIS" and c2="Indianapolis" why is the statement after the if
statement never executed?
If c1.Value = c2.Value then
c1.Offset(0, 6) = c1.Offset(0, 6) + c2.Offset(0, 3)
 
It is never evaluated because the evaluation of text strings is case
sensitive. The easiest way to get around that would be:

If lcase(c1.Value) = lcase(c2.Value) then

HTH,
Keith
 
You could put

Option Compare Text

at the top of the code module to make ALL text comparisons case
insensitive ("A" = "a"). This setting applies to the entire module.

For a specific comparison, use

If StrComp(C1.Value, C2.Value, vbTextCompare) = 0 Then
' strings match
Else
' string don't match.
End If

The third parameter to StrComp can be vbTextCompare to ignore case,
vbBinaryCompare to use case, to use the database comparison settings,
or omitted. If omitted, the Option Compare Text is present in the
module, case is ignored. If omitted and Option Compare Text is not
present in the module, case matters.

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)
 
Thanks Chip, once again you made my day.

Chip Pearson said:
You could put

Option Compare Text

at the top of the code module to make ALL text comparisons case
insensitive ("A" = "a"). This setting applies to the entire module.

For a specific comparison, use

If StrComp(C1.Value, C2.Value, vbTextCompare) = 0 Then
' strings match
Else
' string don't match.
End If

The third parameter to StrComp can be vbTextCompare to ignore case,
vbBinaryCompare to use case, to use the database comparison settings,
or omitted. If omitted, the Option Compare Text is present in the
module, case is ignored. If omitted and Option Compare Text is not
present in the module, case matters.

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)
 
Back
Top