The ultimate miniaturization of future devices will require the use of functional molecules at the nanoscale and their integration into larger architectures. Switches represent a prototype of such functional molecules because they exhibit characteristic states of different physical/chemical properties, which can be addressed reversibly. Recently, various switching entities have been studied and switching of single molecules on surfaces has been demonstrated. However, for functional molecules to be used in a future device, it will be necessary to selectively address individual molecules, preferentially in an ordered pattern. Here, we show that azobenzene derivatives in the trans form, adsorbed in a homogeneous two-dimensional layer, can be collectively switched with spatial selectivity, thus forming a periodic pattern of cis isomers. We find that the probability of a molecule switching is not equally distributed, but is strongly dependent on both the surrounding molecules and the supporting surface, which precisely determine the switching capability of each individual molecule. Consequently, exactly the same lattices of cis isomers are created in repeated erasing and re-switching cycles. Our results demonstrate a conceptually new approach to spatially addressing single functional molecules