A diagrammatic perturbation theory is presented which is applicable to nondegenerate, quasidegenerate, or degenerate zero-order function spaces. The model space, in which the effective Hamiltonian is diagonalized, is selected on a state-by-state basis, and the requirement of a complete model space (all possible distributions of the electrons in the open shells) is dropped. This feature is particularly important if there is more than one open shell, as is the case in most atomic and molecular excited states. The partitioning of the orbitals into two classes, holes and particles, instead of the usual three (core, valence, and particles), leads to a reduction in the number of diagrams and to a greater degree of diagram cancellation. Certain unlinked diagrams appear for incomplete model spaces; the expansion is, however, shown to be size consistent in all cases. An application to the c3Σg+ and C1Σg+ states of He2 near an avoided crossing is described. While the nondegenerate theory diverges in this case and other degenerate theories require a 25-configuration model space, good convergence is obtained by the present method with a three-configuration model space and fewer diagrams.