Application.SetMatchingField method (Project)

Sets the value in the field of selected tasks or resources that meet the specified criteria.

Syntax

expression.SetMatchingField (Field, Value, CheckField, CheckValue, CheckTest, CheckOperation, CheckField2, CheckValue2, CheckTest2)

expression A variable that represents an Application object.

Parameters

Name Required/Optional Data type Description
Field Required String The name of the field to set.
Value Required String The value to which the field is set.
CheckField Required String The name of the field to check.
CheckValue Required String The value to compare with the value of the field specified with CheckField.
CheckTest Optional String The type of comparison made between CheckField and CheckValue. The default value is "equals". Can be one of the comparison strings.
CheckOperation Optional String How the criteria established with CheckField, CheckTest, and CheckValue relate to the second criteria, if specified. The CheckOperation argument can be set to "And" or "Or". The default value is "And".
CheckField2 Required String The name of the second field to check.
CheckValue2 Required String The value to which the second field is set.
CheckTest2 Optional Variant The type of comparison made between CheckField2 and CheckValue2. Can be one of the same comparison strings as CheckTest.

Comparison strings

Comparison string Description
"equals" The value of CheckField equals CheckValue.
"does not equal" The value of CheckField does not equal CheckValue.
"is greater than" The value of CheckField is greater than CheckValue.
"is greater than or equal to" The value of CheckField is greater than or equal to CheckValue.
"is less than" The value of CheckField is less than CheckValue.
"is less than or equal to" The value of CheckField is less than or equal to CheckValue.
"is within" The value of CheckField is within CheckValue.
"is not within" The value of CheckField is not within CheckValue.
"contains" CheckField contains CheckValue.
"does not contain" CheckField does not contain CheckValue.
"contains exactly" CheckField exactly contains CheckValue.

Return value

Boolean

Example

The following example checks for equality of task field Name, changes the value to New Task Name, and then changes the name back to the original.

Sub Set_MatchingField() 
 
 Dim T As Task 
 Dim OldName As String 
 
 'Save the task name 
 Set T = ActiveProject.Tasks(3) 
 OldName = T.GetField(pjTaskName) 
 
 ViewApply Name:="&Gantt Chart" 
 'Change the field to "New Task's Name" 
 SetMatchingField Field:="Name", Value:="New Task Name", CheckField:="Name", CheckValue:=OldName, CheckTest:="equals" 
 ' Set the field to the old name 
 SetMatchingField Field:="Name", Value:=OldName, CheckField:="Name", CheckValue:="New Task's Name", CheckTest:="equals" 
End Sub

Support and feedback

Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.