Forum Discussion

bah73's avatar
bah73
Copper Contributor
Mar 24, 2023

MS Project VBA Help Filtering

Hi,

 

I am applying a column filter then adding a value to an adjacent column.

I problem I am having is when the filter returns no value the code still adds a value to the adjacent column.

This creates a new task line.

The code I need help with is if the filter returns no values to skip to next filter in the code.

I have added some code below.

 

'''''Examples of a filter returning no value and adding format and text to adjacent column creating a new task
'''''When filter returns no value I need to skip to next set of code

'''''Skip if no value returned 
    SetAutoFilter FieldName:="Text30", FilterType:=pjAutoFilterCustom, Test1:="contains", Criteria1:="ALS"
    SetAutoFilter FieldName:="Resource Names", FilterType:=pjAutoFilterIn, Criteria1:="PC-CPINSP"
    SelectTaskColumn Column:="Text3"
    Font32Ex CellColor:=13159680
    SetTaskField Field:="Text3", Value:="CLASSIFIED"
    FillDown
    FilterClear
     

'''''Skip if no value returned   
    SetAutoFilter FieldName:="Text30", FilterType:=pjAutoFilterCustom, Test1:="contains", Criteria1:="ALS"
    SetAutoFilter FieldName:="Resource Names", FilterType:=pjAutoFilterIn, Criteria1:="PC-CRNINSP"
    SelectTaskColumn Column:="Text3"
    Font32Ex CellColor:=13159680
    SetTaskField Field:="Text3", Value:="Crane"
    FillDown
    FilterClear
    
    
'''''Skip if no value returned     
    SetAutoFilter FieldName:="Text30", FilterType:=pjAutoFilterCustom, Test1:="contains", Criteria1:="ALS"
    SetAutoFilter FieldName:="Resource Names", FilterType:=pjAutoFilterIn, Criteria1:="PC-DRONE"
    SelectTaskColumn Column:="Text3"
    Font32Ex CellColor:=13159680
    SetTaskField Field:="Text3", Value:="Drone"
    FillDown
    FilterClear
  • John-project's avatar
    John-project
    Silver Contributor
    bah73,
    Please don't cross-post. Fortunately before answering your question I saw your identical post on the Stack Overflow forum where Rachel already provided an answer.
    John
    • bah73's avatar
      bah73
      Copper Contributor
      Hi John
      Sorry I didn't know cross platforming was a thing.

Resources