Fetching details from the dictionary...

to use in place of; to substitute (a person or role); to represent; to act as a proxy
to exchange; to interchange; to renew
to substitute (person, staff member, player, etc.)
古いパソコンを新しいのに代えた。
I replaced the old computer with a new one.
命に代えても守りたいものがある。
There's something I want to protect even at the cost of my life.
電池を新品に代える必要がある。
I need to replace the battery with a new one.