When should I use that instead of which?
Use that for clauses essential to the meaning of the sentence, and which — with a comma — for clauses that add extra information.
The report that we published yesterday is online. — identifies which report. Remove the clause and the sentence loses its meaning.
The report, which we published yesterday, is online. — there is one report; the timing is a bonus detail. Remove it and the sentence still works.
The grammatical terms are restrictive (essential, that, no commas) and non-restrictive (extra, which, commas).
The difference is not decorative. Consider:
The buildings that were damaged will be demolished. — only the damaged ones. The buildings, which were damaged, will be demolished. — all of them, and incidentally they were damaged.
A reader who knows the convention will take quite different meanings from those two sentences, which is why editors care about it.
The test: read the sentence without the clause. If it still identifies the right thing, the clause is extra — use which and commas. If the sentence becomes vague, the clause is essential — use that.
Two qualifications worth knowing. This is more strictly observed in American English than British, where which is commonly used for restrictive clauses too and is not considered an error. And the commas do most of the work: a restrictive clause with which but no commas is generally clear, whereas commas in the wrong place mislead regardless of the word.
For people, use who rather than either — the colleague who wrote it.
One practical consequence for search and screen readers: because the commas carry so much of the meaning, dictation software and hurried editing frequently drop them and silently change what a sentence claims. It is worth re-reading any sentence where a which clause could plausibly be essential.