I've done this a couple of times now lol
I'm assuming the tank is stocked with fish?
Set up a temporary spot for the fish, such as an extra tank or even a clean Rubbermaid tub. Add a heater and an air stone if you have one, or even run the filter on the tub if it's possible. If not, keep the filter media wet while you're working. Drain some tank water into the tub and catch and add the fish (hardest part especially if you have small fast fish lol).
Then drain the rest of the tank, switch out the substrate, refill, run the filter and heater for a while, a couple of hours or so (the tank will probably be cloudy from the sand), then net the fish back into the main tank. Leave the lights off for the rest of the day so the fish can rest as they'll be a bit stressed.