Galaxies are moving away from each other then how Milkyway and Andromeda galaxy coming towards each other?

The Andromeda Galaxy is approaching the Milky Way at about 684000 mi/hours, making it one of the few blueshifted galaxies. The Andromeda Galaxy and the Milky Way are thus expected to collide in about 3.75 or 4.5 billion years.

Why some galaxies are moving away and why our galaxy+andromeda are coming towards each other ?

-

Here is my answer to a similar question posted on the physics stack exchange website.

Hubble's law (the law that deals with the expansion of the universe) applies to the expansion of space itself, i.e., if two objects stationary to each other that had no force between them were left alone the distance between would increase with time because space itself is expanding. This is what Hubble's law addresses.

In the case of the Milky Way and Andromeda galaxies (and all galaxies for that matter) there is a force between them: gravity. The gravitational force between the Milky Way and Andromeda galaxies has produced an acceleration that is causing the two galaxies to be moving towards each other faster than the space between them is expanding as calculated by Hubble's law. However, the vast majority of galaxies lie far enough away from the Milky Way that the gravitational force between us and them is small compared to the Hubble expansion and Hubble's law dominates.

In short, Hubble's law applies throughout the universe, but localized systems may have enough gravitational attraction between them that the gravitational effects dominate

-

The farther away, the faster the galaxies move away from us. But that's only the overall expansion of the universe. Locally velocities can differ and are to be added to the overall expansion. The Andromeda Galaxy is close enough to Milky Way to be able overcome the overall expansion of space. The Andromeda Galaxy and the Milky Way attract each other by gravity.

Hubble's law applied to Andromeda Galaxy/Milky Way returns an expansion of space of less than 70 km/s, since Hubble's constant is about 70 km/s/Mpc, and the distance is about 2.5 million light-years, less than 1 Mpc (= 3.26 light-years, see Parsec). That speed is slower than the about -300 km/s helio-radial velocity (space expansion already subtracted) of the Andromeda galaxy, hence feasible to overcome.

-