The expansion of the universe is a phenomenon that occurs on large cosmological scales and affects the overall structure of space. It is important to note that the expansion of the universe primarily affects the large-scale structure of space itself, rather than the individual objects within it, such as galaxies.
In the case of the Andromeda galaxy, which is the closest spiral galaxy to our Milky Way, it is currently moving away from us due to the expansion of space. However, it is also gravitationally bound to our local group of galaxies, which includes the Milky Way, Andromeda, and several other smaller galaxies. The gravitational attraction between these galaxies counteracts the expansion of space to some extent.
Given the current rate of expansion, it is estimated that it will take about 4 billion years for the Milky Way and Andromeda to collide and merge into a single galaxy. So, in the scenario you described where it takes 3 million years to travel to Andromeda, it would still be relatively close to its current position. The expansion of the universe would have a minimal effect on the relative distance between our two galaxies over such a short timescale.
However, it's worth mentioning that there are other factors to consider. The motion of galaxies within the local group is influenced not only by the expansion of the universe but also by their individual velocities and gravitational interactions with other nearby objects. These factors can introduce additional complexities and contribute to the overall motion of galaxies.
In summary, while the expansion of the universe causes galaxies to move away from each other on cosmological scales, the motion of individual galaxies within gravitationally bound systems can counteract this effect, allowing them to maintain their relative positions over shorter timescales such as millions of years.