Can you catch a cold by sleeping with a fan on?

No. Colds are caused by your body's susceptibility to a cold virus.

While low humidity in a room might create the proper conditions for some viruses, a fan does not have any effect on the humidity level in a room, as a fan simply pushes air around, it does not alter the air like an air conditioner. A fan blowing directly in your face could potentially dry out your mucous tissue and make it slightly easier for a cold virus to gain entry through cracked tissue, but without the presence of the virus in your immediate environment resulting in your exposure, you will not get a cold no matter how dry your membranes are.

There are a lot of myths and old beliefs from before science fully understood the mechanism of infection by rhinoviruses (the viruses causing the common cold). The idea of being out in the cold weather or in air drafts causing a "weakening" the immune system allowing for infections isn't true.

References/sources:

Dowling HF, Jackson GG, Spiesman IG, Inouye T (1958). "Transmission of the common cold to volunteers under controlled conditions. III. The effect of chilling of the subjects upon susceptibility". [American Journal of Hygiene 68 (1): 59-65.];

Douglas, R.G.Jr, K.M. Lindgren, and R.B. Couch (1968). "Exposure to cold environment and rhinovirus common cold. Failure to demonstrate effect". [New England Journal of Medicine 279.]

Your immune system doesn't need to work hard to keep you warm because immune response isn't responsible for temperature regulation, so that does not put any strain on the immune system or interfere with its ability to fight infections.

The best way to avoid colds is to wash your hands regularly, and steer clear of sick people as best you can.