In both examples, the cell is tested usingIsEmpty() to determine if it should be modified. Please
note the above examples assume that if the cell has an entry, that it is a text entry that should be
modified. Also "c" is used as a range name to refer to the cell in the range being modified.
If you know the specific range to be modified, or can specify a range that encompasses the cells
to be modified, then you can do something like the following instead. This example also
specifies sheet so that the code is not restricted to working on the active sheet or changing to the
sheet containing the range to be modified. It does assume that the sheet is in the active
workbook. Lastly, this example tests the value of each cell versus testing to see if the cell is
empty and uses a With…End With construction to make the code slightly faster. The periods in
front ofValue in this example are needed because of theWith…End With construction. It
makes theValue property refer to cell "c".
Dim c As Range
For Each c In Sheets("my data").Range("A1:A200")
If .Value <> "" Then
.Value = "* " *
10.4 Case Insensitive Comparisons
To make text comparisons in a module case insensitive, put the statement
Option Compare Text
at the top of your module.
Or, you can useLCase() andUCase() to convert your text strings to the same case and then do
str1 = Range("A1").Value
str2 = Range("A1").Value
If UCase(str1) = UCase(Str2) Then
'actions to take if the same
'actions to take if different
If you are usingInStr() to search a string for a matching string, then you have two options to
making the search case insensitive"
Put Option Compare Text at the top of the module, or