Andrew, buy yourself an Excel VBA book, something like Microsoft Excel 2002 Visual Basic for Applications Step by Step There are lots more avalilable. If you can't affor a book, put "VBA tutorial" into Google and take your pick from the free websites that turn up.
I am assuming that you have done some programming before.