How will Andromeda collide with Milky Way in spite of Hubble's law? According to Edwin Hubble our Universe is expanding because he noticed that other galaxies are moving away from us. But then how Andromeda galaxy will collide with Milky Way in ~4.5 billion years, as it should also move away from us?

I am some bit confused, please help me.

 A: According to Hubble's law

Objects observed in deep space — extragalactic space,
   10 megaparsecs (Mpc) or more — are found to have a redshift,
   interpreted as a relative velocity away from Earth;
   all the galaxies move away from each other.
The law is often expressed by the equation $v = H_0 D$,
  with $H_0$ the constant of proportionality — Hubble constant —
  between the "proper distance" $D$ to a galaxy [...]
  and its velocity $v$ [...].
The Hubble constant is about $70 \text{ (km/s)/Mpc}$.

This law is an average law, applicable to the large distances only
($D \geq 10 \text{ Mpc}$, see above), and thus for large velocities
($v \geq H_0 \cdot 10 \text{ Mpc} = 700 \text{ km/s}$).
It totally neglects the chaotic individual movement of galaxies
relative to their neighbor galaxies nearby.
Therefore Hubble's law is not applicable to the Andromeda galaxy
which is only $0.78 \text{ Mpc}$ away from the Milky Way (our galaxy).
Due to the individual movement of these
galaxies within the Local Group of galaxies
the Andromeda galaxy happens to approach us with a velocity
of $300 \text{ km/s}$.
This is still a small velocity compared to the velocities
where Hubble's law is applicable.
A: Because Andromeda is so close, a mere 2.5 million light years away, it is gravitationally attracted to the local group (which incudes the Milky Way), and its proper motion masks the effect of cosmic redshift. As the Andromeda galaxy and the Milky Way are moving toward each other, we see a blueshift in the spectrum of Andromeda.
