The relative pronouns that and which have caused considerable pain to people who are subject to the red pen of the English teacher or the copy editor. This discomfort is easily avoided, but first you need to know what "relative" pronouns are.
A relative pronoun like that or which introduces a relative clause, a group of words with a subject and predicate that attaches itself to a word the writer wishes to explain within a larger sentence. For instance, in the sentence "A relative pronoun is one that introduces a relative clause," the relative clause "that introduces a relative clause" is attached to the word one and provides information about it.
Fussy grammarians claim that there is a hard and fast rule distinguishing that from which. In real life, however, writers at the highest level of skill will happily interchange that and which on the basis of sound alone. There is nothing wrong with this, but many people -- like English teachers and editors -- look down their noses at this sort of thing. If you want to please them, you need to know what they think the hard and fast rule is.
Unfortunately writers often have a hard time figuring out what is expected of them because fussy grammarians use unnecessarily difficult jargon to explain their rule. They will tell you that that rules a restrictive clause and which rules a nonrestrictive clause without telling you what restrictive and nonrestrictive mean.
A restrictive clause is one you absolutely have to have in order to understand what is being discussed. If you have ten cats and only one cat is on the table, you would say "the cat that is on the table" to distinguish it from all the other cats.
A nonrestrictive clause is one you don't have to have in order to understand what is being discussed. It provides extra information, but not essential information. If you have only one cat, and that cat is on the table, you would say "the cat, which is on the table," because you don't need to define which cat you're talking about.
So here at last is the "hard and fast rule," which isn't really all that hard and fast:
The relative pronoun that introduces a restrictive relative clause. Simply translated:
that defines something that needs defining
The relative pronoun which introduces a nonrestrictive relative clause. Simply translated:
which gives extra information about something that doesn't need defining
Here are a couple of quick and easy ways to get that and which straight without having to think about grammar:
You can assume that if the clause is set off by a comma, it should take which and if it's not, it should take that.
The online Guide to Grammar and Style by Jack Lynch provides an excellent test:
Use "by the way" after your relative pronoun. If it makes sense, it should be which. If it doesn't, it should be that.
Example: Of all my cats, this is the one that is on the table
Test: Of all my cats, this is the only one that [by the way] is on the table.
Doesn't make sense! The naughtiness of this specific cat distinguishes it from the other cats who are not at the moment being naughty. That is correct.
Example: My cat that is white is on the table.
Test: My cat that [by the way] is white is on the table.
Does make sense! Color is not essential to understanding naughtiness. Which is correct.