You can, but you need a monitor with DVI and VGA inputs. VGA is normally a blue colour and DVI is normally white.
You connect one computer with the VGA cable and the other to the DVI port using either the DVI port if there is one, or a DVI to VGA converter which costs very little.
Make sure that the monitor you pick has an easy way to switch between DVI input and VGA input. Some are not simple to switch. You just need a small button on the front or sides that quickly switches between the two.
The best ones have an independent button that will switch between the two.