Using
-----Original Message-----
"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.
.
Thanks for the code Harlan, appreciate it.
Yes, perhaps I could have explained it better but I
figured by examing the code one could figure that it was
not returning a true in the "Like" test when it should
have.
I know what you are saying about using a long but the
reason I use an integer is because the multiple files that
I deal with are sometimes not consistent because sometimes
different users do different things and I can not be
guaranteed that I will be dealing with a consistent format
from spreadsheet to spreadsheet. Sometimes there are
blank rows, sometimes not and I can't be sure the end of
sheet indicator is where it is supposed to be or that some
user didn't accidentally enter something in the very last
cell in the spreadsheet area some 64000 rows down. It has
happened before so when I write code for Excel I have to
write it in a way that assumes chaos will happen. So I use
an integer because I would rather have the code crap out
at the upper limit of an integer rather than continue on
to the very last available row, it just saves time and
aggravation.
Regardless, I like the efficiency of your code and I have
incorporated into my sub-procedure. I don't write code
for Excel that often so I'll be the first to admit I don't
always know the best way to do things. So again, thanks
for your help I appreciate it.
|