If you have studied enzymes its a similar concept. Cells have proteins on the surface of their cell which hormones bind to (called receptors) The receptor must be a complimentary shape to the hormone for it to bind. Only target cells have the receptor with the complimentary shape so only these cells will be affected.