Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Ayo Ayo is offline
external usenet poster
 
Posts: 489
Default Help with if statement

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)
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 395
Default Help with if statement

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

"Ayo" wrote:

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)

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,124
Default Help with if statement

One way

If UCase(Range("c1")) = UCase(Range("c2")) Then MsgBox "ok"

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Ayo" wrote in message
...
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)


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Help with if statement

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)



On Mon, 31 Aug 2009 15:11:02 -0700, Ayo
wrote:

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)

  #5   Report Post  
Posted to microsoft.public.excel.programming
Ayo Ayo is offline
external usenet poster
 
Posts: 489
Default Help with if statement

Thanks Chip, once again you made my day.

"Chip Pearson" wrote:

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)



On Mon, 31 Aug 2009 15:11:02 -0700, Ayo
wrote:

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)




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Vlookup, if statement, maybe an and statement Jennifer Excel Discussion (Misc queries) 1 February 26th 10 03:30 AM
IF statement inside a SUMIF statement.... or alternative method Sungibungi Excel Worksheet Functions 3 December 4th 09 06:22 PM
Reconcile Bank statement & Credit card statement & accounting data Bklynhyc Excel Worksheet Functions 0 October 7th 09 09:07 PM
Embedding an OR statement in an IF statement efficiently Chatnoir11 Excel Discussion (Misc queries) 4 February 2nd 09 08:12 PM
appending and IF statement to an existing IF statement spence Excel Worksheet Functions 1 February 28th 06 11:00 PM


All times are GMT +1. The time now is 05:38 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"