VBA VBA VBA

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

A
Andrew Owenson 👤 Member for 17 years 11 months

Niek

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

 

Andrew

A
Andrew Owenson 👤 Member for 17 years 11 months

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

N
Niek Zonneveld 👤 Member for 21 years 2 months

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

D
Darren Kosa 👤 Member for 18 years 3 months

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

A
Andrew Owenson 👤 Member for 17 years 11 months

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

N
Niek Zonneveld 👤 Member for 21 years 2 months

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

Forum Sponsor

Top Posters

Julian Pegg
1 posts
Peter Nagy
2 posts
Raymund de Laza
17 posts
Syed_Asad
0 posts
Tony Greyvenstein
0 posts
Ahmed Al-Jubouri
13 posts
Umar Alvi
3 posts
Sibusiso Mahlalela
0 posts
Michael Samanyayi
3 posts
Simon Gumede
0 posts