You've not closed your for/next loop

For r = 4 to m ............................. needs a next r before the first red end if