Need to know how many tasks returned after appling filter

L

luvgreen

Greetings!

Is there a way to get count of tasks returned from applying filter? Thanks.
 
J

JackD

Sub countOfFilteredTasks()
SelectAll
On Error GoTo ErrorHandler
MsgBox ActiveSelection.Tasks.Count
Exit Sub

ErrorHandler:
MsgBox "No tasks returned by filter"

End Sub

-Jack


luvgreen said:
Also how can I know if filter returns nothing. Thanks.
Thanks.
 
J

John

luvgreen,
I use the following to count the tasks in a filter,
SelectTaskColumn
ActiveSelection.count

There are various way to tell if the filter returned a null set.
Probably the most common is when a loop is used to do something with the
data in the tasks returned by the filter.
For Each t in ActiveSelection.Tasks
If Not t is Nothing Then
[do what you need]
Else
[returned set was null]
End If
Next t

If you are not in a loop you could also simply trap the error with code
such as this:
On Error Resume Next
Set Area = ActiveSelection.Tasks
If Err <> 0 Then
[the returned set is null]
Else
[there is at least one task in the returned set]
End If

Hope this helps.
John
 
M

Marty

Thanks for the help Jack. You are awesome.

JackD said:
Sub countOfFilteredTasks()
SelectAll
On Error GoTo ErrorHandler
MsgBox ActiveSelection.Tasks.Count
Exit Sub

ErrorHandler:
MsgBox "No tasks returned by filter"

End Sub

-Jack



Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top