You've gotten the basics from directorik and knightly.
If you got complete coverage of the scene you should have many more versions of the line(s) available. Extract the audio from all of the alt/unused takes. Organize them according to shot type - CU, 2-Shot, etc.** First try the takes that most closely sound like the one with the "bad" audio. For example, if the bad audio is a 2-shot try the other 2-shots first. If they don't work then try the alts from the CUs because you can add reverb to better match the 2-shot. Besides off-mic problems, you can use this process to fix all sorts of extraneous sounds interfering with the dialog, or a mumbled line, or an indistinct word, or even adding just a "T" or an "S" to the beginning or ending of a word.
This is where "ears," skills and tools come into play. I use Vocalign for this process. With Vocalign you take a guide "snapshot" of the original line of dialog and then Vocalign performs a time alignment of the target line (dub) of dialog. Vocalign LE ($300) has "loose," "normal" and "tight" alignment algorithms, Vocalign Pro ($600) has variable algorithms, and ReVoice Pro ($800) does amazing things.
Even with Vocalign you may have to manually "microscope" edit the dialog, shortening or lengthening spaces (time stretch and compression) and/or words or syllables (don't forget the cross-fades). If you don't have Vocalign you may/will have to edit every space and syllable to get the alt dialog line to match the original. I have had to Vocalign individual words in a line of dialog, as well as manually shorten and lengthen spaces and syllables, and then perform the alignment process on the entire line.
The replacement dialog has to sync with the picture seamlessly as well as smoothly blend in sonically. I have reconstructed entire scenes. This is not a quick and easy process, and why dialog editing takes so much time. I usually spend about one third of all my time on the dialog edit. But the film rests on the dialog, which is why I preach so much about getting the production sound right.
** BTW, this is another reason to label all of you clips properly; it saves LOTS of time. The dialog/sound editor doesn't have to listen to every single line in order to organize it.