Code evaluating TRUE when I believe it should be false

I have this piece of code in my procedure.  I have watches set up for rng4 and rng6.
Before this line fires, rng4's value is "No Data" and rng6's value is "Description", however my IF statement keeps being evaluates as True.  Any ideas why? I believe me statement is correct to evaluate rng4 as False (false positive)

                            If rng6 <> "" And Not (rng4 = "no data") Then 'move through blank data cells in current series
                                While rng5.Value = ""
                                Set rng5 = rng5.Offset(0, 1) 'attrib data move right
                                Set rng6 = rng6.Offset(0, 1) 'attrib header move right
                                Wend
                                GoTo Next_Item
                            End If
                        

Open in new window

Watches.jpgSheet-Data.jpg
MCaliebeAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Martin LissOlder than dirtCommented:
Try this

If rng6 <> "" Then
 IF rng4 <> "no data" Then 'move through blank data cells in current series
                                While rng5.Value = ""
                                Set rng5 = rng5.Offset(0, 1) 'attrib data move right
                                Set rng6 = rng6.Offset(0, 1) 'attrib header move right
                                Wend
                                GoTo Next_Item
                            End If
End If
MCaliebeAuthor Commented:
I'll give that a shot. Any idea why the statement is evaluating wrong?
Martin LissOlder than dirtCommented:
Without a sheet with which to test I can't say, but generally I go out of my way to avoid "Not" logic.
OWASP: Threats Fundamentals

Learn the top ten threats that are present in modern web-application development and how to protect your business from them.

Martin LissOlder than dirtCommented:
I just noticed that you are evaluating for "no data" while your data has "No Data" so try the following (It's VB6/VBA code)

If rng6 <> "" And Not (UCase(rng4) = "NO DATA")

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
MCaliebeAuthor Commented:
Well, the UCase line did work.  Can you tell me why?  

Also, out of frustration, I change the data in my sheet to "No Data", however the original statement I was trying to test was "***No Data***".

Is this format evaluated the same way?  Do * in the string make a difference?
Martin LissOlder than dirtCommented:
Because it's an exact, case-sensitive, match so "no data" is not equal to "No Data" and "No Data" is not equal to "***No Data***". I'm sure that .net has compare methods that don't care about case or that will return True if "No Data" is anywhere in "***No Data***" but I'm not familiar with .Net.
NorieAnalyst Assistant Commented:
You could try the Like operator if you want to use wildcards/find partial matches, though I'm not sure if it's case sensitive or not.
Martin LissOlder than dirtCommented:
This article talks about case sensitivity in comparisons.
MCaliebeAuthor Commented:
Thanks for the help and the additional info.  Onto evaluate my next bug!
Martin LissOlder than dirtCommented:
You're welcome and I'm glad I was able to help.

In my profile you'll find links to some articles I've written. One of them is about using Debug and .Net probably has something similar and no doubt improved.
Marty - MVP 2009 to 2015
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.