The grammatical distinctions between use of which and of that are treated here; it was just the third question asked on this site!
In which may head a relative clause in which the which must stand as the object of the preposition in.
He put the book in that cupboard.
There are four ways of expressing he put the book in as a relative clause modifying cupboard.
- with a ‘null-relativizer’ → That is the cupboard he put the book in.
- with that → That is the cupboard that he put the book in.
- with which → That is the cupboard which he put the book in.
- with which and ‘pied-piping’ → That is the cupboard in which he put the book.
‘Pied-piping’ is the technical term for a Wh- relative pronoun’s dragging along the preposition of which it is the object when it ‘moves’ to the head of a relative clause from the position which its referent would occupy in the corresponding main clause.
PIED-PIPED NOT PIED-PIPED
. . . he put the book in it. . . . he put the book in it.
. . . he put the book [in which] . . . he put the book in [which]
[in which] he put the book [which] he put the book in
Note that only Wh- pronouns may pied-pipe their prepositions. Relative that may not pied-pipe:
∗ That is the cupboard in that he put the book.
Note, too, that an apparent ’preposition‘ which acts as a particle in a true phrasal verb may not be pied-piped:
okThis is the form which you need to fill in.
∗This is the form in which you need to fill.
18th century writers on grammar deprecated what we today call the ‘stranded’ preposition—a preposition ending a clause, as in ##1, 2 and 3 above—in the most formal prose. Their objection was aesthetic, not grammatical: it was an age when both poetry and prose were still written primarily for the ear, not the eye, and they felt that in speech unstressed syllables and function words weakened what should be the strongest part of a sentence.
In the 19th century this preference was rigidified by schoolteachers into a hard ‘rule’ forbidding stranded prepositions, and that rule was widely enforced down to quite recent times. Some still maintain it today; but you may generally ignore it.
This does not mean, however, that pied-piping is to be avoided; in fact, recent corpus studies have shown that pied-piping is still more common with Wh- relatives than stranding even in spoken English. And pied-piping, in contexts where it is permitted, has the great advantage of making the relationship between the preposition and its object clearer. It should be employed wherever many words would separate the Wh- relative from the preposition:
ok That is the chest in which the long-lost private papers of James Boswell were for almost two centuries stored.
awkThat is the chest which the long-lost private papers of James Boswell were for almost two centuries stored in.
∗ marks an utterance which is not grammatically acceptable.
awk marks an utterance which is awkward and should be avoided.