1. Each galaxy has its own orbital path.
2. Space itself is expanding equally everywhere.
So some simple maths.
The orbit of Andromeda is bringing it closer to the Milky Way. Why? Because its movement is much faster than the expansion of space between it and us. One cancels out the other and the difference allows it to approach closer.
More distant galaxies are inevitably moving away from us, because the expansion of space exceeds the speed of their orbital paths, even when their orbital path is facing in our direction.
The expansion of space is also cumulative. So the farther away a galaxy is from us, the more the distance between it and us grows. Few galaxies are close enough for their orbits to make a difference.
Andromeda is relatively close-by (our nearest galactic neighbour), and so is one of the very few galaxies whose orbit can outpace the expansion of space.
Galaxies can and do collide. Some parts of space are much denser than others, and where galaxies are close together there is more chance that their orbits will bring them into collision.