If the monster is performing a ranged attack, it will only move toward a hex where it is within range to perform its best possible attack.
Once the target is within range for best possible attack the monster will stop moving even if it has movement left.
A monster adjacent to a focused enemy will move away from it until it can perform the ranged attack without Disadvantage (usually this will be just one space).
Example below: This archer would move 1 space away before doing a ranged attack.
When forced to choose, a monster will prioritize losing Disadvantage on its focused enemy over maximizing its attack on secondary targets (if targeting multiple enemies).
Example above: If this archer had a Range 2, Target 2, it would still move back 1 space and only target the Mindthief. Even though if it stayed there it would hit both Mindthief and Spellweaver, it would be at a disadvantage vs the Mindthief.
Even if a monster cannot move into attack range, it will still use its movement to get as close as possible to its focus.