Preparation of a quantum state with one molecule at each site of an optical lattice