Quoting from a paper by Roth and Vakil ($\mathrm{cd}$ stands for cohomological dimension):
Let $S$ be $\mathbb{P}^2$ blown up at a point, and let $X$ be the affine cone over some projective embedding of $S$. Let $Z\subset X$ be the affine cone over the exceptional divisor of the blowup. Then $Z$ is of codimension one in $X$, but $\mathrm{cd}(X\backslash Z) = 1$, so in particular it is not affine. This shows that, conversely, the complement of a Weil divisor in an affine scheme need not be affine...