to use this code, uncomment the option compare binary statement, and put it at the top of the source file. The following example uses the option compare statement to set the case-insensitive text sort order as the default string comparison method.
In order to make vba case-insensitive, you need to put option compare text at the beginning of the module. First, we will look at the standard vba behavior without this option set.
Option compare text sub comparetext() dim foo as string dim bar as string case insensitivity foo abc bar abc debug. Print (foo bar) prints true still differentiates accented characters foo bc bar abc debug. Print (foo bar) prints false b still comes after a or foo bar b debug.
To insert the code, press altoption-f11, select insert module and paste the following option compare text sub optioncomparetext( ) dim rcell as range for each rcell in range(a1a10) if rcell cat then msgbox rcell.
compare argument of strcomp is optional, but in case of case sensitive match, we can utilize this, and the option is vbbinarycompare.
use string1 as the first argument string2 variable as the second argument and use vbtextcompare as the comparison argument to this statement.
Print abc abc prints true end sub option compare binary -- this is the default! Sub foo2 debug.
Use option compare text if you write option compare text at the top of your module, all the vba comparisons with in that module will use text comparison instead of binary comparison.