When the excitation energies of an ensemble of geometries, computed by the complete active space self‐consistent field (CASSCF) or other CAS‐based methods, are convoluted to obtain the absorption spectrum, it is advisable that all the considered geometries have the same molecular orbitals within the active space. In this work, we present an algorithm that evaluates the molecular orbital overlap matrix between a previously selected reference geometry, with the desired active space, and each of the sampled geometries. Based on the value of the overlap matrix elements, the algorithm determines whether one or more pairs of molecular orbitals of the sampled geometry have to be swapped for a subsequent CASSCF calculation. We have applied the developed algorithm to CASSCF and CASPT2 calculations for sets of geometries of the five canonical nucleobases in vacuum and in aqueous solvent. The algorithm shows a very good efficacy since it recovered the correct active space for 90% of the geometries which presented undesired molecular orbitals in the active space after the first CASSCF wavefunction optimization. In addition, the importance of having the same orbitals within the active space for all the geometries is discussed based on the corrected and uncorrected density of states for the nucleobases.