Consulting

Results 1 to 3 of 3

Thread: Need code help for highlighting rows with If statement

  1. #1
    VBAX Newbie
    Joined
    Nov 2014
    Posts
    2
    Location

    Need code help for highlighting rows with If statement

    Hello,
    I have the following code (which works) for coloring rows when tasks complete % is below the expected % complete (which is a custom field):

    Sub SelectTaskRows()
    Dim tskT As Task
    For Each tskT In ActiveProject.Tasks
    Select Case tskT.Number7
    Case Is <= 0
    SelectRow row:=tskT.ID, RowRelative:=False
    Font32Ex CellColor:=&H9DF2BA
    Case 0.1 To 30
    SelectRow row:=tskT.ID, RowRelative:=False
    Font32Ex CellColor:=&H46F5FF
    Case 30.1 To 100
    SelectRow row:=tskT.ID, RowRelative:=False
    Font32Ex CellColor:=&H3760FE
    End Select
    Next tskT
    End Sub

    I would like to insert an If statement, to only color the rows green/yellow/red if the task is a milestone.
    Being the VBA infant that I am, I cannot get it to work (I'm apparently missing pieces).

    Could someone please help?
    Thank you!
    Caroline

  2. #2
    Banned VBAX Newbie
    Joined
    Sep 2015
    Posts
    5
    Location
    You solved your problem? if Yes then how?

  3. #3
    VBAX Newbie
    Joined
    Nov 2014
    Posts
    2
    Location
    Quote Originally Posted by BrynjulfRasm View Post
    You solved your problem? if Yes then how?
    Yes. Here is what I have:

    Sub SelectTaskRows()
    Dim tskT As Task
    For Each tskT In ActiveProject.Tasks
    If tskT.Milestone = True Then
    Select Case tskT.Number7
    Case 0 To 10
    SelectRow row:=tskT.ID, RowRelative:=False
    Font32Ex CellColor:=&H9DF2BA
    Case 10.1 To 40
    SelectRow row:=tskT.ID, RowRelative:=False
    Font32Ex CellColor:=&H46F5FF
    Case 40.1 To 100
    SelectRow row:=tskT.ID, RowRelative:=False
    Font32Ex CellColor:=&H3760FE
    End Select
    End If
    Next tskT
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •