thank you very much for your answers Mark
Excuse my bad English.
Attached you the complete code. The link to the solution set I had already seen and I tried but did not work either.
I have given many laps do not know if the code attached will be entirely correct.