Is there a way to make this code more effective?

Can you help me out on fixing this ineffective and inefficient code?

"Ineffective" means it's not producing the desired effect. If that's the case you'll need to describe what it's (not) doing compared to what you want it to do.

Or is it working correctly (ie it's effective) and you want it to be more efficient, only?

(If it's already doing what you want, it can't be more effective than that.)