Electrons in an atom occupy discrete energy levels. An electron can only be excited to another level if it absorbs the exact amount of energy as the difference between the two levels. Therefore the energy of the photon it absorbs needs to be of a specific energy to excite it and, as E = hf, its energy needs to be a specific frequency.