Help: Activecell within Do loop problem

D

DavidShepherd

Please help
I am attempting some programming and I am having trouble with the
activecell command within a do loop.
What I am attempting to do is go through a row and have an event occurr
on particular cell values. The problem is that when I attempt to the use
the activecell.value command to trigger the loop to stop excel does not
appear to read the cell value and thus stop the loop. It does not
appear to read the cell value property.
Can you advise me whether I am doing something completely incorrect, or
whether there is another way to have the program read a cell value and
trigger an output.

Here is an example of the code I am using

For a = 1 To n
Application.Goto reference:="project_inclusion_start"
c = 0
Do Until ((ActiveCell.value) ="yes")
e = a + c
ActiveCell.Offset(a + c).Activate
If (ActiveCell.value="yes") Then Exit Do
c = c + 1
If c < 5 Then Exit Do
Loop

ActiveCell.Offset(0, -1).Activate
plyearsV(a) = ActiveCell.value
ActiveCell.Offset(0, -1).Activate
namesv(a) = ActiveCell.value
Next a

The code does the following
It goes to a reference, and moves down a row untill it finds a cell
with the value "yes"
When this cell is fouund it adds the two values offsetting the cell to
a different array.
Then it goes back to the start and moves down to the cell after this
one.
The problem is that the activecell.value function is always reading as
"no", even when the input value is "yes".

Thanks
Dave
 
B

Bob Phillips

Haven't tested it as I don't have any idea of the data, but maybe don't do
the final activating

For a = 1 To n
Application.Goto reference:="project_inclusion_start"
c = 0
Do Until ((ActiveCell.Value) = "yes")
e = a + c
ActiveCell.Offset(a + c).Activate
If (ActiveCell.Value = "yes") Then Exit Do
c = c + 1
If c < 5 Then Exit Do
Loop

plyearsV(a) = ActiveCell.Offset(0, -1).Value
namesv(a) = ActiveCell.Offset(0, -2).Value
Next a


--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"DavidShepherd" <[email protected]>
wrote in message
news:D[email protected]...
 

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

Top