Skip to content

VBA VBA VBA

Andrew OwensonMember for 18 years 4 months
Created
6
2
0

I have a filter which selects ceratain activities. Can anyone advise on how to write a macro which takes the resultant activities from this filter and colour the bars say green.

 

Many Regards

 

Ab=ndrew

6 replies

Oldest first
  1. 0
    Niek Zonneveld ·

    Andrew,I would go with a

    Andrew,

    I would go with a structure like below.

    For all tasks that meet your filter criteria you have the field "Marked" set to "Yes" by the macro.

    The next step is to create a view where the bar for a 'marked' task is shown in a different color.

    HTH

    Niek.

    --------------------

    Sub Color_line()

        Dim t As Task

        Dim Blank_Line As Integer

    'This macro loops through all selected lines and changes the color based on the line meeting certain filter criteria.

     

        For Each t In ActiveSelection.Tasks

            If t Is Nothing Then

                Blank_Line = Blank_Line + 1

                ElseIf filter criteria Then

                Tsk.Marked = "Yes"

    Else

            End If

        Next t

    End Sub

  2. 0
    Andrew Owenson ·

    Niek   Thankyou for your

    Niek

     

    Thankyou for your interest.

    This is what I have done.

    I am using the field flag20 as my yes/no - I have set a bar in the view to be green if flag 20 is yes. I first clear the flag20 field - that works. I then run a filter - that works. But wehn I run the next bit where I want the filtered bars flag20 filed to be yes it only makes the first bar yes and does not change any more. Any ideas.

     

    Regards

     

    Andrew

     

    Sub Colourfiltergreen()

    ' Macro Colourfiltergreen

    ' Macro Recorded 13/09/11 by Andrew Owenson.

     

    Dim jTasks As Tasks

    Dim jTask As Task

     

    'clear the flag field

    For Each jTask In ActiveProject.Tasks

        If Not jTask Is Nothing Then

            jTask.Flag20 = "No"

        End If

    Next jTask

       

    'set the flag field for the selected task

    FilterApply Name:="Near Critical"

    For Each jTask In ActiveSelection.Tasks

         If Not jTask Is Nothing Then

            jTask.Flag20 = "Yes"

        End If

    Next jTask

     

    FilterApply Name:="All Tasks"

    End Sub

  3. 0
    Darren Kosa ·

    Hi Andrew, If you're already

    Hi Andrew,

    If you're already using Filters for your macro, have you thought about just formatting a new Task Bar using Bar Styles?

    Saves things getting overly complicated by going down the VBA route.

    Regards,

    Darren Kosa

  4. 0
    Niek Zonneveld ·

    Andrew,I guess it won't

    Andrew,

    I guess it won't automatically select the tasks you've filtered (see line in bold), so you loop through 1 active line only.

    It's probably safer is to use the filter criteria (hard coded) in the loop itself. (less flexible, probably but...)

    H.T.H.

    Niek.

    *****************

    'set the flag field for the selected task

    FilterApply Name:="Near Critical"

    For Each jTask In ActiveSelection.Tasks

         If Not jTask Is Nothing Then

            jTask.Flag20 = "Yes"

        End If

    Next jTask

  5. 0
    Andrew Owenson ·

    Darren   What Im after is an

    Darren

     

    What Im after is an additional bar type alongside the two bars in a critical path view ie, critical = red 0TF blue for activities with Tf bigger than 4days and a near critical activity with TF less than 4. I have added this bar as a flag and what I would like to be able to do is have the chart update automatically to show these bars.

     

    Andrew

  6. 0
    Andrew Owenson ·

    Niek Many thanks for your

    Niek

    Many thanks for your help, it has set me on the correct path.

     

    Andrew

Log in or join to reply

ProjectControls.com is free to join. Members can post questions, reply, vote and follow discussions.

Existing members: your original username and password still work. Forgot password?