MySQL: Updating or closing existing rows in a table and/or inserting new rows?
This is beyond what SQL can do.  Your application (which needs to be something more of a programming language than Excel) should orchestrate the task.