We study spiral wave dynamics in the presence of nonexcitable cells in two-dimensional (2D) and three-dimensional (3D) excitable media, described by the Aliev-Panfilov model. We find that increasing the percentage of randomly distributed nonexcitable cells can prevent the breaking up of a spiral wave into a complex spatiotemporal pattern. We show that this effect is more pronounced in 2D than 3D excitable media. We explain the observed 2D vs 3D differences by a different dependence of the period and diastolic interval of the spiral wave on the percentage of nonexcitable cells in 2D and 3D excitable media.