Final code on "Apply to selection"