What do you mean by "the board works perfectly fine on the uploadee code". Are you saying that you can successfully upload to the Mega after connecting it to your PC?
I understand now.Do you see a new port in the Arduino IDE's Tools > Port menu after you plug in the Mega?If not, make sure you have the USB cable fully inserted into the Mega and the PC.You may have a damaged/defective or charge-only USB cable. Try a different one.USB 3 ports can sometimes cause problems. Try a USB 2.0 port or a USB 2.0 hub connected to a USB 3 port.
Are you saying that you tried a different board with the same USB cable and same USB port on the same PC and the problem did not occur with that board?