From van der Waals' equation: $$(p + \frac{an^2}{V^2})(V - nb) = nRT\\ p = \frac{nRT}{V - nb} - \frac{an^2}{V^ 2}$$$$(p + \frac{an^2}{V^2})(V - nb) = nRT\\ \color{brown}{p} = \frac{nRT}{V - nb} - \frac{an^2}{V^ 2}$$
Compressibility factor is the ratio of volume of real gas to ideal gas: $$Z= \frac{pV}{nRT} = \frac{V}{V - nb} - \frac{an}{VRT}$$$$Z= \frac{V}{V_{\text{ideal}}} = \frac{\color{brown}{p}V}{nRT} = \frac{V}{V - nb} - \frac{an}{VRT}$$