It's good to know the solution worked fine. However, you should understand it before using it.
Two tips I can give you are to use the PRINT command I included but left commented and read this article from Jeff Moden: Cross Tabs and Pivots, Part 2[/url]
If you still have doubts on the code, feel free to ask.