Couldn't modify partition map on macOS

Couple weeks ago my brother's MacBook Pro started with some problems and it was damaging external drives like USB and SD cards, the system was corrupting the partition map of these devices and wasn't possible re-format the partition.
He asked me if I know I way to recover the devices, so I tried reformat the partition using Disk Utility, but it shows this error:

Solution:

If the device is not completely damaged the solution for this is to create a new partition map on the device, this is also possible using Disk Utility using the hidden option Show All devices:

Now you will able to select the device, make sure you select the device and not the partition, right click and click on Erase:

After you click on Erase you will see a screen similar to the image below and you will able to use the device again.


Via command line

You also can do this via command line, you need to identify the path of the USB, you can do it using the command:

diskutil list

My USB is the /dev/disk2, the command to erase the USB device is the following:

diskutil eraseDisk ExFAT USBNAME /dev/disk2