How to customize a percentage field?

H

Helen

I want a custom field which is a percentage value. I hope users can pickup
and/or input in the field just like the '% Complete' one. Can I realize it
without extra programming? Thanks for any reply.
 
J

Jim Aksel

Please provide a specific example of what you are trying to accomplish.
Percentage is 100 times the division of two numbers. You can enter a custom
formula by right clicking on a custom field (say Number1) and selecting
Customize/Fields.. in the context menu.

Do you want an entry in this field to drive values in another field?
Do you want to be able to key in a value or have project calculate it? In
the custom fields it is basically one or the other, not both.
--
If this post was helpful, please consider rating it.

Jim Aksel, MVP

Check out my blog for more information:
http://www.msprojectblog.com
 
J

John

Helen said:
I want a custom field which is a percentage value. I hope users can pickup
and/or input in the field just like the '% Complete' one. Can I realize it
without extra programming? Thanks for any reply.

Helen,
Yes you can do that. You will need to either use a formula in a custom
field (e.g. Text1), if the data to calculate the percentage is from the
same task line, or VBA if you the data to calculate the percentage is
from other task lines. So, what exactly do you want to do?

John
Project MVP
 
H

Helen

Thanks Jim

What I need is another '% Complete' field which already exists in the
Project. I hope users can input any number between 0 to 100 (better display
with a '%'), and I do want the number in this field can drive values in other
custom fields. Thanks.

Helen
 
H

Helen

Thanks John,

Sorry maybe I wasn't clear before. The percentage number is entered not
calculated. But I hope it has a limitation from 0 to 100. And I will use it
for other calculation of the same task line.

Thank you!
Helen
 
J

Jim Aksel

You can do this with a formula and perhaps a macro.
I had hoped you'd give us a real example rather than this "drive other
columns" general type of thing... it saves us all a lot of time getting to
the best answer for you.

So here is my example. You want to key in a %Complete into Number1. You
want the Number1 column to drive the value of the number of bags of mortor
you need to consume on your project. So, in another custom column (say
Number2) you have the total number of bags of mortor purchased for that task.
When you enter a % in the Number1 column, it is the percentage of the bags
you believe were consumed for the task so far. You want to calculate the
number of bags remaining and display that in Number 3.

You place a formula in the Number3 field: (1-[Number1]/100)*[Number2]
Entering a value in the Number1 column drives the number in Number3.

Now, you want to limit the values in Number1 to 0...100. Can't do that with
a formula. You will need a VBA maco to run whenever the value changes and
make sure the value is within "spec." If it is not within Spec, you need to
decide what you want to do. For example, if they enter 115 do you just round
it to 100 or do you send up a message box that tells them they can't do that.
Same with negative values.

Here is some code to get you started. The challenge is handling non-numeric
data in the text1 column. I didn't try to format the Number1 column as
percent, I just did it in Text1. See if this is helpful, it runs every time
anything in the project changes.

Private Sub Project_Change(ByVal pj As Project)
Dim tsk As Task
For Each tsk In ActiveProject.Tasks
'check for blank lines
If Not tsk Is Nothing Then
If tsk.Text1 <> "" Then
'validate text1 contains a number
If IsNumeric(tsk.Text1) Then
'is the number from 0 to 100?
If tsk.Text1 >= 0 And tsk.Text1 <= 100 Then
tsk.Text1 = FormatPercent(tsk.Text1 / 100, 0)
Else
'input is numeric but out of bounds
MsgBox ("TaskID: " & tsk.ID & " must contain a numeral from 0 to 100
in Text1 field")
End If
Else
'Non numeric input in Text1
'You need to write code here on how to handle this condition
End If 'end of numeric check
End If 'check for blank text1
End If 'check for blank line
Next tsk
End Sub

--
If this post was helpful, please consider rating it.

Jim Aksel, MVP

Check out my blog for more information:
http://www.msprojectblog.com
 
J

John

Helen said:
Thanks John,

Sorry maybe I wasn't clear before. The percentage number is entered not
calculated. But I hope it has a limitation from 0 to 100. And I will use it
for other calculation of the same task line.

Thank you!
Helen

Helen,
It looks like Jim jumped in and gave you a complete rundown on the
options. Hope this takes care of your issue.

John
Project MVP
 

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