Code very slow

L

Lucas Soler

The code below takes about 5-10 minutes for 1,000 tasks. How can I make it
go faster?

For Each T In ActiveSelection.Tasks
If T.Text1 = "Yes" Then
T.PhysicalPercentComplete = T.Number1 * 100

Else
T.PhysicalPercentComplete = T.PercentWorkComplete
End If
Next
 
L

Lucas Soler

I've noticed that assigning the value to the fields is what is slowing it
down (T.PhysicalPercentComplete = T.Number1 * 100).
 
J

Jan De Messemaeker

Hi,

The question is: how did you make it so slow?
Tried it, takes about a second.
Do you have an event driven macro installed that reacts to change?
Could it be automatic resource leveling?
I can't think of any other reason immediately.
HTH
 
B

Brian K - Project MVP

Jan said:
Hi,

The question is: how did you make it so slow?
Tried it, takes about a second.
Do you have an event driven macro installed that reacts to change?
Could it be automatic resource leveling?
I can't think of any other reason immediately.
HTH
--
Jan De Messemaeker
Microsoft Project Most Valuable Professional
http://users.online.be/prom-ade/
+32-495-300 620

I was thinking the same thing. I have had macros that went through
every task and then every assignment and recurssed several times
through the list of 2000 or 3000 tasks and never took anywhere near as
long. There has to be something else, an on change event or something.
 
J

John

Lucas Soler said:
I've noticed that assigning the value to the fields is what is slowing it
down (T.PhysicalPercentComplete = T.Number1 * 100).

Lucas,
I agree with Jan, code that simple and straightforward should run in a
"flash". However you might try this simple change to speed things up.
Before going through the loop, turn calculation off. After the loop turn
it back on. If the file is large and complex, sometimes automatic
calculation can significantly slow down a seemingly simple process.

Hope this helps.
John
Project MVP
 
J

JackD

Something else must be going on. How much memory do you have? Do you have
any other applications open? It should take a second or two at the most.
 

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