ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Ignore Case without using Regular Expressions (https://www.excelbanter.com/excel-programming/428924-ignore-case-without-using-regular-expressions.html)

ExcelMonkey

Ignore Case without using Regular Expressions
 
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

Bernd P

Ignore Case without using Regular Expressions
 
If UCase(Array1(0)) = UCase(Array2(0)) then

or

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

Regards,
Bernd

Dave Peterson

Ignore Case without using Regular Expressions
 
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



ExcelMonkey wrote:

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


--

Dave Peterson

Chip Pearson

Ignore Case without using Regular Expressions
 

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)


On Mon, 25 May 2009 14:28:01 -0700, ExcelMonkey
wrote:

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


ExcelMonkey

Ignore Case without using Regular Expressions
 
Thank-you!

EM

"Dave Peterson" wrote:

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



ExcelMonkey wrote:

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


--

Dave Peterson



All times are GMT +1. The time now is 07:27 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com