There's nothing wrong with the code you've posted, if there is a problem it's going to be the code within the loops.

Getting incorrect results can happen for a number of reasons - if you are comparing values then accuracy/rounding might be a cause.

A major reason for things eg ranges, columns etc being skipped is because they are being deleted at some point.

That can sort of throw the looping off a bit.