Guild of Project Controls: Compendium | Roles | Assessment | Certifications | Membership

Tips on using this forum..

(1) Explain your problem, don't simply post "This isn't working". What were you doing when you faced the problem? What have you tried to resolve - did you look for a solution using "Search" ? Has it happened just once or several times?

(2) It's also good to get feedback when a solution is found, return to the original post to explain how it was resolved so that more people can also use the results.

VBA VBA VBA

6 replies [Last post]
Andrew Owenson
User offline. Last seen 1 year 21 weeks ago. Offline
Joined: 18 Jun 2008
Posts: 68
Groups: None

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

Replies

Andrew Owenson
User offline. Last seen 1 year 21 weeks ago. Offline
Joined: 18 Jun 2008
Posts: 68
Groups: None

Niek

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

 

Andrew

Andrew Owenson
User offline. Last seen 1 year 21 weeks ago. Offline
Joined: 18 Jun 2008
Posts: 68
Groups: None

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

Niek Zonneveld
User offline. Last seen 2 years 23 weeks ago. Offline
Joined: 17 Mar 2005
Posts: 188
Groups: None

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

Darren Kosa
User offline. Last seen 7 years 31 weeks ago. Offline
Joined: 8 Feb 2008
Posts: 256
Groups: None

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

Andrew Owenson
User offline. Last seen 1 year 21 weeks ago. Offline
Joined: 18 Jun 2008
Posts: 68
Groups: None

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

Niek Zonneveld
User offline. Last seen 2 years 23 weeks ago. Offline
Joined: 17 Mar 2005
Posts: 188
Groups: None

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