Can this code be smaller

I think I will close this one because it seems that I cannot explain what I want in English.

Everyone thanks