Nearly every melody line has underlying harmonies (chord) which reflect the notes in each bar.E.g.,in a bar of C-E-F-G, there are notes which make Cmaj., so that chord will fit in that bar. In a bar with, for example, an F and A, this will give you more scope - Fmaj., Dmin., G9 come to mind.                                                                      

Often there's a note which won't fit a chord, and if it's on a weak part of the bar, it won't count towards that chord.Weaker parts could be 2nd or last beat, or maybe the 'and' between beats.1st and 3rd (in 4/4) are places to look for components of a chord.When you move out of key, as in C - Gb,there are no common notes, so either change chord within the bar, or possibly use a Bb note, which could fit both C7 and Gb. Really need that sample.