Try changing the Loop statement with the last Endif.