Can you please help me out with the code/ function, for the same thing to get automated.

Thanks in advance,
Gajre...