One more loop question
Bob,
I'm sure this problem is nowhere near as confusing as my explanation my make
it seem...
For each name in column A, I need to look down a list for various codes in
column L. Once I find a valid code, I want to quit looking, and enter what
I found (via the case statement) in column P of the first row in which that
name appeared. It has to be in the row with the _first_ instance of the
name because once I get this Sub to work, I am going to delete rows so that
each name appears only once (keeping the row where the name first appears).
In my testing, this happened, as all of mine had THis, That or were
empty
which i9s what the Case statement tells it to.
I probably should have mentioned that not all cells will have a valid code
in them...I'm picking through the garbage that I don't care about.
The reason for looking for the Null in the first Case statement is because I
know that if I find a Null, the rest of the cells in column L for that
particular name will be Null too... so I just want to quit looking, set my
FoundFlag to True and move on to the next name.
The why is because you had an If Else Endif. The If evaialuated the
current
row, whereas the Else reset Agtname. But each case looped to the next
item,
so the Else did not also go through the cell evaluation, whereas it does
in
my example because it is an indecent if, before the Case evaluation.
Oh, I get it now... but how can I reset the Agtname _and_ have it evaluated
in the first instance? I tried to use "offset" to set it to the name on
the _next_ row, but it still skipped the first instance of a new name.
If possible, I'd really like to stick close to the code I've got. I'm sure
that there is always going to be a technically "better" method, but I really
need to learn to do this myself, & it's hard to get a handle on when I keep
"starting over".
Thanks!
Patti
"Bob Phillips" wrote in message
...
"Patti" wrote in message
...
Hi Bob,
You are right that this now evaluates every row...but now it won't find
the
flag for each name unless it appears in the same row as the first
instance
of the name.
So if I have in column A: Column L:
Smith blah
Smith This '( my flag)
I thought I might have messed this bit up when I moved the Found flag, but
I
couldn't remember the exact requirment from your previous post. Explain
what
you want again. FRom this post I read it that you want to highlight the
first row with another value in column L, but your case statement
evaluates
empty as a value. If the offset value is empty would this count as found,
or
should it just be This, That, etc.
I want column P of the *first* row where Smith occurs to say "I found
This!"
In my testing, this happened, as all of mine had THis, That or were empty
which i9s what the Case statement tells it to.
The use of the oCurrent variable was actually a tip I got from you, to
capture the row where I found the first instance of a new name. And of
course it works great.
Now stop that, throwing what I said back at me <VBG. If I recall, you
would use that to save the cell and then use that cell object thereafcter,
but the way you have implemented the code is to save all of the values
separately (i as the row, AgtName as the agent name), so saving the cell
as
well is superfluous, not wrong, just overkill.
(sorry if I broke any rules of netiquette by staring a new
thread...nearly
a
week has passed since I last posted & I thought it unlikely that the
last
would be revisited).
Who cares. I personally think there is a lot of fluff about netiquette.
There are some practices that make life simpler, but they are not rules.
Anyway, I just don't understand the "why" behind it skipping a row on
the
change of name. As long as I'm stuck with this problem, I am trying to
make it a good learning experience...
The why is because you had an If Else Endif. The If evaialuated the
current
row, whereas the Else reset Agtname. But each case looped to the next
item,
so the Else did not also go through the cell evaluation, whereas it does
in
my example because it is an indecent if, before the Case evaluation.
|