Their are numerous number of reasons for creating viruses and spywares, the main reasons are NOT to annoy people and mess up your hardware/software etc however the reasons that i could think of are
(a) Viruses, especially worms have innate ability to replicate themselves over a network. So, by placing a single worm i am getting the control of possibly thousands of workstations. Now, why is it important to control this number of workstations. Answer is simple, DoS or Denial of Service Attack. I don't know how much you know about it, but to put it in simple words it's a brute attack where you access a specific website with a lot of workstations simultaneously, ultimately bringing the website down. Why would one do it? Mainly because of money, people pay hackers to do this stuff on their competitors and possibly your PC is part of a DoS attack right now.
(b) Personal Information, a very solid reason for making viruses. Virus coders would make virus to get your personal information and then would sell it to other companies. Sometimes it involves even credit card numbers etc.
(c) I would agree with
infinity_grimm, it's true most of the biggest companies in Anti-Virus software department actually make and release viruses to capture the market. They say its Business, and sadly it IS!
(d) Lastly, people do it for fun,vandalism, religious or belief extremism etc.