To remove a virus from an external hard drive without losing data, you need to avoid formatting and follow the instructions below instead:
Install reliable anti-malware software on an isolated computer.
Connect the external hard drive to the computer.
Scan it using the installed anti-malware software application.