SOLVED

Changing cost rate by using macro

%3CLINGO-SUB%20id%3D%22lingo-sub-2753448%22%20slang%3D%22de-DE%22%3EChanging%20cost%20rate%20by%20using%20macro%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2753448%22%20slang%3D%22de-DE%22%3E%3CP%3EIn%20a%20project%20I%20need%20to%20calculate%20both%20the%20sales%20and%20the%20costs%20incurred.%20I%20have%20solved%20this%20using%20different%20cost%20rates%20(A%20and%20B).%20Now%20I%20am%20looking%20for%20a%20way%20to%20quickly%20change%20the%20cost%20rate%20from%20A%20to%20B%20and%20vice%20versa%20using%20a%20macro%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20the%20following%20macro%2C%20but%20I%20always%20get%20an%20error%20message%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESub%20Kostensatz_nach_A_%C3%A4ndern()%20%3CBR%20%2F%3E%20'%20Macro%20Kostensatz_nach_A_%C3%A4ndern%20%3CBR%20%2F%3E%20ViewApplyEx%20Name%3A%3D%22Operation%3A%20Use%22%2C%20ApplyTo%3A%3D0%20%3CBR%20%2F%3E%20SelectTaskField%20Row%3A%3D2%2C%20Column%3A%3D%22Cost%20Rate%20Table%22%20%3CBR%20%2F%3E%20SetResourceField%20Field%3A%3D%22Cost%20Rate%20Table%22%2C%20Value%3A%3D%22A%22%20%3CBR%20%2F%3E%20SelectTaskField%20Row%3A%3D0%2C%20Column%3A%3D%22Cost%20Rate%20Table%22%2C%20Height%3A%3D23%20%3CBR%20%2F%3E%20FillDown%20%3CBR%20%2F%3E%20ViewApplyEx%20Name%3A%3D%22%26amp%3BGantt%20Chart%22%2C%20ApplyTo%3A%3D0%20%3CBR%20%2F%3E%20End%20Sub%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESince%20this%20is%20an%20English%20language%20forum%2C%20I%20am%20attaching%20two%20pictures%20of%20the%20cost%20rate%20table.%20I%20think%20then%20my%20problem%20will%20become%20clear.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20for%20your%20help%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2753823%22%20slang%3D%22en-US%22%3ERe%3A%20Changing%20cost%20rate%20by%20using%20macro%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2753823%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1155476%22%20target%3D%22_blank%22%3E%40Uli60%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EFirst%20of%20all%20even%20though%20VBA%20code%20elements%20are%20all%20in%20English%20(by%20default)%2C%20please%20understand%20that%20any%20reference%20to%20views%20or%20fields%20(i.e.%20string%20value)%20must%20be%20in%20the%20language%20being%20used%2C%20in%20your%20case%2C%20German.%20Perhaps%20you%20already%20know%20that.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIt%20would%20have%20been%20helpful%20to%20know%20what%20error%20message%20you%20received%20but%20on%20further%20inspection%20of%20your%20macro%20code%2C%20I%20see%20you%20are%20attempting%20to%20set%20a%20resource%20field%20in%20a%20task%20based%20view%20(i.e.%20Task%20Usage).%20That%20probably%20explains%20the%20error%20you%20see.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHowever%2C%20it%20isn't%20quite%20clear%20exactly%20what%20you%20are%20trying%20to%20do.%20Based%20on%20the%20statement%20that%20selects%20a%20task%20field%20with%20a%20height%20of%2023%20leads%20me%20to%20believe%20you%20are%20trying%20to%20change%20the%20assignment%20cost%20rate%20tables%20for%20all%20the%20assignments%20in%20the%20whole%20plan%20or%20only%20for%20a%20given%20task.%20But%2C%20perhaps%20not.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20pictures%20you%20attached%20don't%20really%20tell%20anything%20other%20than%20there%20are%20separate%20cost%20rates%20for%20the%20%22A%22%20and%20%22B%22%20cost%20rate%20tables.%20A%20picture%20or%20screen%20shot%20of%20the%20Task%20Usage%20view%20and%20a%20more%20detailed%20explanation%20of%20what%20you%20want%20to%20do%20will%20help%20me%20understand%20your%20intent%20so%20I%20can%20offer%20assistance.%3C%2FP%3E%3CP%3EJohn%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2755232%22%20slang%3D%22de-DE%22%3ERe%3A%20Changing%20cost%20rate%20by%20using%20macro%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2755232%22%20slang%3D%22de-DE%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F917748%22%20target%3D%22_blank%22%3E%40John-project%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHello%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20task%20is%20as%20follows%3A%20%3CBR%20%2F%3E%20I%20have%20material%20(material%201%20and%202)%20that%20I%20sell%20at%20the%20price%20of%20X%20%E2%82%AC%20%2Funit%20and%20buy%20at%20the%20price%20of%20Y%20%E2%82%AC%20%2Funit.%3CBR%20%2F%3EI%20have%20stored%20the%20sales%20price%20in%20the%20Ressource%3A%20Table%20as%20cost%20rate%20A%2C%20the%20purchase%20price%20as%20cost%20rate%20B.%3C%2FP%3E%3CP%3EIn%20the%20Gantt%20chart%2C%20I%20have%20assigned%20the%20material%20to%20the%20tasks%20(Task%201%20and%202).%20In%20the%20cost%20column%20%2CI%20now%20see%20the%20values%20of%20the%20sales%20price%20(default%20in%20project%20to%20access%20cost%20rate%20A).%3C%2FP%3E%3CP%3EI%20have%20added%20the%20Cost%20Rate%20Table%20column%20to%20the%20Task%3A%20Usage%20view%20(screenshot).%3C%2FP%3E%3CP%3EThe%20macro%20should%20now%20do%20the%20following%3A%20It%20should%20change%20all%20values%20in%20the%20column%20Cost%20rate%20table%20from%20A%20to%20B%20in%20the%20view%20Task%3A%20Usage%2C%20so%20that%20I%20can%20see%20the%20purchase%20costs%20in%20the%20Gantt%20chart.%20It%20works%20manually.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20hope%20it%20is%20a%20little%20bit%20clearer%20and%20you%20understand%20my%20problem.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Occasional Contributor

In a project I need to calculate both the sales and the costs incurred. I have solved this using different cost rates (A and B). Now I am looking for a way to quickly change the cost rate from A to B and vice versa using a macro?

 

I have the following macro, but I always get an error message:

 

Sub Kostensatz_nach_A_ändern()
' Makro Kostensatz_nach_A_ändern
ViewApplyEx Name:="Vorgang: Einsatz", ApplyTo:=0
SelectTaskField Row:=2, Column:="Kostensatztabelle"
SetResourceField Field:="Kostensatztabelle", Value:="A"
SelectTaskField Row:=0, Column:="Kostensatztabelle", Height:=23
FillDown
ViewApplyEx Name:="&Gantt-Diagramm", ApplyTo:=0
End Sub

 

Since this is an English language forum, I am attaching two pictures of the cost rate table. I think then my problem will become clear.

 

Thanks for your help

 

7 Replies

@Uli60 

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

@John-project 

 

Hello,

 

The task is as follows:
I have material (material 1 and 2) that I sell at the price of X € /unit and buy at the price of Y € /unit.
I have stored the sales price in the Ressource: Tabelle as cost rate A (Kostensatz A), the purchase price as cost rate B (Kostensatz B).

In the Gantt chart, I have assigned the material to the tasks (Task 1 and 2). In the cost column (Kosten), I now see the values of the sales price (default in project to access cost rate A).

I have added the Kostensatztabelle (Cost Rate Table) column to the Vorgang: Einsatz (Task: Usage) view (screenshot).

The macro should now do the following: It should change all values in the column Kostensatztabelle (Cost rate table) from A to B in the view Vorgang: Einsatz (Task:Usage), so that I can see the purchase costs in the Gantt chart. It works manually.

 

I hope it is a little bit clearer and you understand my problem.

 

 

Okay, that helps. Did you try the macro code I posted? Does it do what you need and if not, what should be changed?
John
Hi, sorry, but I cannot find the macro. Where did you post it?
Uli
It's part of the response I posted on Sept 15, part of the last paragraph.
John

@John-project 

John, you are brilliant! This is exactly what I need! The macro runs great! Many, many thanks and have a great weekend. Be back next time, I'm sure I'll have many more questions.

Love from Germany
Uli

best response confirmed by Uli60 (Occasional Contributor)
Solution
Uli,
You're welcome and thanks for the feedback. If I answered your question, please consider marking my response as the answer.
John