title: MS Project VBA - how to avoid errors when a filter returns nothing
body: <p>My code applies a filter to the project (to show only activities for a specific resource in the next week) and I need to trap the instances where the filter returns nothing.</p>
  <p>I have found this <a href="https://stackoverflow.com/questions/9639807/error-on-activeselection-tasks">article</a>  which leads to this <a href="https://docs.microsoft.com/en-us/previous-versions/office/developer/office-2003/aa169315(v=office.11)?redirectedfrom=MSDN" rel="nofollow noreferrer">MS Entry</a>.   From this I came up with the test:</p>
  <pre><code>If ActiveSelection.Tasks Is Nothing Then GoTo NextResource
  </code></pre>
  <p>to exit the current resource loop and go to the next, however, this doesn't work.  The error (424) is only generated when I try to use the ActiveSelection</p>
  <p>Code snip for context:</p>
  <pre><code>For Each Resource In Proj.Resources
      If Not (Resource Is Nothing) Then
      If Resource.Work &gt; 0 Then
       'setup and apply filter for each resource
       FilterEdit name:=&quot;filter4people&quot;, TaskFilter:=True, Create:=True, OverwriteExisting:=True, FieldName:=&quot;Start&quot;, Test:=&quot;is less than or equal to&quot;, Value:=finish, ShowInMenu:=True, ShowSummaryTasks:=True
       FilterEdit name:=&quot;filter4people&quot;, TaskFilter:=True, FieldName:=&quot;&quot;, NewFieldName:=&quot;% Complete&quot;, Test:=&quot;is less than&quot;, Value:=&quot;100%&quot;, Operation:=&quot;And&quot;, ShowSummaryTasks:=True
       FilterEdit name:=&quot;filter4people&quot;, TaskFilter:=True, FieldName:=&quot;&quot;, NewFieldName:=&quot;Resource names&quot;, Test:=&quot;contains&quot;, Value:=Resource.name, Operation:=&quot;And&quot;, ShowSummaryTasks:=True
           
       FilterApply &quot;filter4people&quot; ' apply the filter
          If Not (Err.Number = 91 Or Err.Number = 0) Then            ' saw an error applying filter
               Err.Clear                   ' clear out the error
               GoTo NextResource           ' jump to the next resource
           End If
  
      Application.SelectSheet 'need to select the sheet so that ActiveSelection works properly
      
      'CStr(ActiveSelection.Tasks.Count)
      If ActiveSelection.Tasks Is Nothing Then GoTo NextResource
  </code></pre>