Forum Discussion
Changing cost rate by using macro
- Sep 18, 2021Uli,
You're welcome and thanks for the feedback. If I answered your question, please consider marking my response as the answer.
John
First of all even though VBA code elements are all in English (by default), please understand that any reference to views or fields (i.e. string value) must be in the language being used, in your case, German. Perhaps you already know that.
It would have been helpful to know what error message you received but on further inspection of your macro code, I see you are attempting to set a resource field in a task based view (i.e. Task Usage). That probably explains the error you see.
However, it isn't quite clear exactly what you are trying to do. Based on the statement that selects a task field with a height of 23 leads me to believe you are trying to change the assignment cost rate tables for all the assignments in the whole plan or only for a given task. But, perhaps not.
The pictures you attached don't really tell anything other than there are separate cost rates for the "A" and "B" cost rate tables. A picture or screen shot of the Task Usage view and a more detailed explanation of what you want to do will help me understand your intent so I can offer assistance.
Nonetheless, anticipating what your response to the above will be, here is a macro that will convert costs for all resource assignments in a plan using either Cost Rate Table "A" or Cost Rate Table "B", based on user input. I even converted the messages to German 🙂
Sub CostRateChg()
'macro by John - Project , 9/15/21
Dim t As Task
Dim a As Assignment
Dim Val As Single
Val = InputBox(Prompt:="Kosten- oder Verkaufswerte anzeigen?" & vbCr _
& "Geben Sie „0“ für Kosten oder „1“ für Verkäufe ein", Title:="Kostensatz-Umrechner")
For Each t In ActiveProject.Tasks
If Not t Is Nothing Then
For Each a In t.Assignments
a.CostRateTable = Val
Next a
End If
Next t
End Sub
John