Got any Excel/VBA Questions? Excel Help
Stop Case Sensitivity in Excel VBA Macro Code
By default, Excel VBA code is case sensitive and uses Binary comparisons. This means that "Cat" and "cat" are not seen as being the same. There are many times however, where you like Excel VBA to not use Binary comparisons and have "Cat" = "cat". This can be done in at least 2 ways.
We can use the Ucase function to ensure all text we compare will be in upper case. Take the example macro below which will show a message box if it encounters any cell in A1:A10 of the active sheet that contains any case variation of the word "CAT".
Sub CompareText() Dim rCell As Range For Each rCell In Range("A1:A10") If UCase(rCell) = "CAT" Then MsgBox rCell.Address & " has " & rCell & " in it" End If Next rCell End Sub
Option Compare Text
The other method we can use will make ALL procedures in a specified Module non-case sensitive. We do this by placing the words Option Compare Text at the very top of the Module we wish to make non-case sensitive. For example, any Procedures placed within the same Module as the Procedure below will no longer be case sensitive. To make ALL procedures within the Module case sensitive again we would replace Option Compare Text with Option Compare Binary
Option Compare Text
Sub OptionCompareText() Dim rCell As Range For Each rCell In Range("A1:A10") If rCell = "CAT" Then MsgBox rCell.Address & " has " & rCell & " in it" End If Next rCell End Sub
|Index to Excel VBA Code|
|TextBox for Numbers Only|
|TextBox for Text Only|
|Using Variables in Excel VBA Macro Code|
|Excel VBA Variables Scope and Lifetime|
|Worksheet Names Stored In Cells For Excel Formula References|
See also Index to Excel VBA Code and Index to Excel Freebies and Lesson 1 - Excel Fundamentals and Index to how to… providing a range of solutions.
Click here to visit our Free 24/7 Excel/VBA Help Forum where there are thousands of posts you can get information from, or you can join the Forum and post your own questions.For those veteran players who form the gambling community for years there are Novomatic online pokies to try again some legendary titles like Book of Ra Deluxe, Sizzling Hot and Lucky Lady’s Charm Deluxe and other games that were extremely popular 10-15 years ago. And to accompany the online pokies Australia there is also Wazdan, which is a quite young provider offering 52 games of contemporary creative design and visual effects. Finally 777 Pokies Igrosoft Russian games offer 5 reels and traditional unique style that Australian players can enjoy in Sweet Life, Island 2 and Crazy Monkey 2.