Ucase and Lcase conditions in macros & Making macros smart

  • Thread starter Thread starter Zak
  • Start date Start date
Z

Zak

Please advise if there is a code that will always lookup any condition
regardless of the case it is in. For example, i found my macro wasnt picking
up every condition when ran and that was because i hadnt got all the format
correct i.e. i did "today" in my code when the text was displayed as "Today"
in the worksheet (so it didnt find it). is there a way that the macro
recognises even if something hasnt been stated in the correct case?

Also, i heard come codes can stop working after a few times.. is this
correct? how can i make my codes 'solid' so they dont ever stop working if
everything stays the same, or if something does change like the cell/row
number.. how can one combat this?

thanks.
 
Zak,

No there isn't so one way is to convert to upper or lower before comparing
like this

Select Case UCase(r.Value)
Case "HEDRA"
myvalue = "AP"

Mike
 
You can put everything in the came case.

Example:

For Each c In myRange
If LCase(c) = "hello" Then
'Do something
End If
Next

If LCase(Range("A1") = LCase(Range("B6") Then
'Do something
End If
 
Need more parentheses.


If LCase(Range("A1")) = LCase(Range("B6")) Then
'Do something
End If
 
You could also use strcomp(). It has a parm that you specify that says you want
a text (not case-sensitive) compare.

Another option is to use:

Option Compare Text

At the top of each module. This goes before any subroutine or function.
 

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

Back
Top