Ignore Case without using Regular Expressions

E

ExcelMonkey

Can I compare two text strings and ignore case without using Regular
Expressions? Is there a regular VBA text function I can use?

If IgnoreCase(Array1(0)) = IgnoreCase(Array2(0)) then
'Do something

End if

Thanks

EM
 
B

Bernd P

If UCase(Array1(0)) = UCase(Array2(0)) then

or

If LCase(Array1(0)) = LCase(Array2(0)) then

Regards,
Bernd
 
D

Dave Peterson

You can use lcase():
if lcase(array1(0)) = lcase(array2(0)) then
or use ucase()

Or you could use
if strcomp(array1(0),array2(0),vbTextCompare) = 0 then

Or you could force every string comparison to be case-insensitive by adding a
line to the top of the module:

Option Compare Text
 
C

Chip Pearson

Use the StrComp function and specify text (case insensitive)
comparison:

If StrComp(Array1(0), Array2(0), vbTextCompare) = 0 Then
' equal
Else
' not equal
End If

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

ExcelMonkey

Thank-you!

EM

Dave Peterson said:
You can use lcase():
if lcase(array1(0)) = lcase(array2(0)) then
or use ucase()

Or you could use
if strcomp(array1(0),array2(0),vbTextCompare) = 0 then

Or you could force every string comparison to be case-insensitive by adding a
line to the top of the module:

Option Compare Text
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top