Excel VBA Case-Sensitive check

Could you help me compare the contents of a cell with a string, trim the cell contents to ignore spaces and also ignore the case?? The following code works.. how would you modify it?? Thanks

If (range("'all defects'!A1").Value <> "Defect Type" Or _
        range("'all defects'!B1").Value <> "Defect ID") Then
        MsgBox "The input for 'all defects' was not expected. Please refer to the 'sample input' sheet and ensure each column is labeled as usual."
        Exit Sub
    End If

Open in new window

Who is Participating?

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

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.

If (LOWER(TRIM(range("'all defects'!A1").Value)) <> "defecttype" Or LOWER(TRIM(range("'all defects'!B1").Value ))<> "defectid") Then
JC_LivesAuthor Commented:
that looks like it will work perfectly, but now I get a compile error: sub or fuction not defined...
The code that you've provided it's part of a sub or function?
Introduction to R

R is considered the predominant language for data scientist and statisticians. Learn how to use R for your own data science projects.

JC_LivesAuthor Commented:
yes, part of a sub
Check if the number of ) is right...
JC_LivesAuthor Commented:
Now I have,

If (LOWER(Trim(range("'all defects'!A1").Value)) <> "defecttype" Or _
        LOWER(Trim(range("'all defects'!B1").Value)) <> "defectid") Then

which returns "sub or function not defined" in excel vba 2003...
If (LOWER(TRIM(range("'all defects'!A1").Value))) <> "defecttype" Or LOWER(TRIM(range("'all defects'!B1").Value )))<> "defectid" Then
JC_LivesAuthor Commented:
I copied your code and just added a ")" before the "Then", but the compiler gives an error; I think possibly we had the right amount of brackets in your first recommendation.  

Also when the code fails based on your first recommendation, it highlights the word "LOWER".  

Thanks for your help btw
JC_LivesAuthor Commented:
I gues it was with the function lower... this code worked:
LCase(Trim(range("'all defects'!A1").Value)) <> "defect type") Then...

Thanks for the solution though, it worked perfectly except for lower doesn't seem to be recognized by my version of excel...
Sorry, I made the code in Excel and in Excel the function is Lower, but in VBA is Lcase! Sorry! :)

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
JC_LivesAuthor Commented:
no worries :) thx for the help!
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 Development

From novice to tech pro — start learning today.