2

Very specific question. I got a task to learn vba, but i cant really find anything for my problem.

screenshot of how it looks in project

Basically if the column "Sammelvorgang" says "Nein", the Column "Text7" should contain the Value of "Nr." of that row

Im looking through the basics of VBA but i cant find a solution to target a specific column or a specific row.

Sub schedule_Number()

Dim tsk As Task

For Each tsk In ActiveProject.Tasks
    
    If Not (tsk Is Nothing) Then
    
        If (tsk.Sammelvorgang.Value = "Nein") Then
        
        tsk.Text7 = tsk.Nr
                    
        End If
        
    End If
    

Next tsk

End Sub

Thanks for the help

Rachel Hettinger
  • 7,927
  • 2
  • 21
  • 31
Polarus
  • 31
  • 1

1 Answers1

1

There is a difference between the displayed value (always a string) and the stored value (date, string, number, etc). In VBA it is simpler to use the stored value. In this case Sammelvorgang is Summary (I believe) which is a boolean, so the code can be written as such:

Sub schedule_Number()

Dim tsk As Task
For Each tsk In ActiveProject.Tasks
    
    If Not (tsk Is Nothing) Then
        If Not tsk.Summary Then
            tsk.Text7 = tsk.ID
        End If
    End If
    
Next tsk

Unfortunately, in VBA the object names, properties, methods are all in English. It might be possible to use the FieldNameToFieldConstant method of the Application object to derive the field ID from the native language field names. (I don't have any non-English versions to test this, however).

Then with the Field ID, the GetField method can be used to return the display value (string).


Here is the English-language documentation: FieldNameToFieldConstant and GetField.

Rachel Hettinger
  • 7,927
  • 2
  • 21
  • 31