Matt
Thank you for your response and apologies for not responding sooner.
Yes, the aim of the code was to get elements that have a shared parameter applied to that element category.
Having had a few days away from a computer I have had time to reflect on the problem and realised that even though you can add shared parameters to a project that does not necessarily mean there are any elements for that category present in the project.
For example, add a shared parameter to Category, Door and if there are no doors in the project/project browser then the filter will not find the element and consequentially the shared parameter.
Once again thank you for your response.