Thread: Using "Like"
View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Harlan Grove[_5_] Harlan Grove[_5_] is offline
external usenet poster
 
Posts: 97
Default Using

"Ben Martens" wrote...
...
. . . What I pasted into the posting was
the portion of code that wasn't working working. By
examining the code you should be able to tell that when
the code finds the string "salaries" or "salary" it is to
put an "S" in the corresponding cell in column CM.


OK, so what do you mean by 'this code doesn't work'? Does it do nothing when it
should do something? Does it throw runtime errors? Does it open Internet
Explorer to the Dancing Hamsters web site? Details help.

Given the code you provided in your original posting, it strikes me that what
you're doing could be done more economically as


Dim liRow As Long 'it *SHOULD* be a long integer breakpoints or no
Dim liCol As Long
Dim strFoo As String

For liRow = 9 To ActiveSheet.Rows.Count 'restrict as needed

strFoo = Cells(liRow, 2).Value

For liCol = 4 To 12 Step 2
strFoo = strFoo & Cells(liRow, liCol).Value
Next liCol

If InStr(1, strFoo, "salary", 1) * InStr(1, strFoo, "salaries", 1) 0 Then
Cells(liRow, 13).Value = "S"
End If

Next liRow


One possible reason your Like expressions don't work the same in different
modules is that these different modules could have different Option Compare
settings. If Option Compare Binary, "DODA" Like "*od*" is FALSE, but with Option
Compare Text, "DODA" Like "*od*" is TRUE. The Like operator only functions in
the context of the containing module's settings, so there's no way for Like to
work case-insensitive if the module is set for binary text comparison. When
you're only looking for literal substrings, it's better to use InStr which can
be set for case-sensitive or case-insensitive operation on a call by call basis.

So, what are your respective module settings? Is all your data in lower case or
does the it vary from file to file?

--
To top-post is human, to bottom-post and snip is sublime.