Does gravity keep nearby galaxies from flying apart in space expansion? On a large scale, the universe expansion pulls galaxies apart while gravity keeps galaxies from expanding. So there seems to be a certain scale, at which the expansion and gravity roughly cancel each other. Within a galaxy gravity wins, but remote galaxies fly apart.
What happens if galaxies are close to each other? I know Andromeda is not a good example, as it is already on a collision course with Milky Way, but generally, do neighboring galaxies of the same group tend to be kept together by gravity or do they fly apart with the expansion of the universe? At what scale does the expansion finally overcome gravity?
 A: Yes, galaxy clusters can remain bound together despite the expansion of the universe. 
Analysing the balance between expansion and gravitational attraction produces an estimate where test particles remain bound in circular orbit around a larger mass if $2GM_{obj} \geq \beta^* H_0^2 r_0^3$ where $\beta^*\approx 5.3$, producing the criterion $$\frac{M_{obj}}{10^{12} M_\odot} > 3h_{70}^2 \left( \frac{r_0}{1 \mathrm{Mpc}} \right)^3.$$ The Milky Way has a sphere of influence is 0.7 Mpc, while a typical star of $0.5 M_\odot$ (with no other competition) has a sphere of influence 55 pc across. A less restrictive bound uses 1.18 rather than 3. 
See this paper for a comparison with actual supercluster data. It also looks at non-circular orbits, where things are more complicated.
A: As a supplement to the other answer:
In GR, the gravitational field of a spherically symmetric mass distribution in an expanding universe dominated by a cosmological constant is described by the Schwarzschild-deSitter metric:
$$ ds^2 = -(1-\frac{2G M}{c^2 r }-\frac{\Lambda r^2}{3})c^2dt^2 + \frac{1}{1-\frac{2G M}{c^2 r }--\frac{\Lambda r^2}{3}}dr^2+r^2d\theta^2+r^2\cos^2\theta d\phi^2$$
where


*

*$M$ is the total mass of the mass distribution

*$\Lambda$ is the cosmological constant (approx. $1.11\cdot10^{-52} m^{-2}$ according to Planck data.)

*$G$ is the gravitational constant

*$c$ is the speed of light


By solving the geodesic equation for this metric, one can find the radius $r$ where a test mass can stay stationary. This radius will mark the maximum radius of influence of the mass; only inside this radius is it possible to have bound orbits. The result is simply
$$ r= \left(\frac{3GM}{c^2\Lambda}\right)^{1/3} $$
or with numerical values for all constants
$$ r = 111 \left(\frac{M}{M_{\odot}}\right)^{1/3} pc $$
This corresponds to the less restrictive bound given in the other answer.
