Yes you can, that is the purpose of diode
D1 on the RAMPS board.
It should be noted that if the RAMPS 1.4 does not have diode
D1 then the Mega2560 will/can not be powered via the RAMPS board and it is necessary to power the Mega2560 separately, for example via the USB.
See 184.108.40.206 Power for the Arduino Mega board on the RAMPS 1.4 RepRapWiki page:
Power for the Arduino Mega board
The RAMPS 1.4 has a 1N4004 diode labeled D1 which allows 12V to feed
and power the Arduino Mega 2560 board. This diode is installed in most
pre-assemble boards, thus the Arduino board is powered by the Ramps by
When the RAMPS is not powered or if the diode is not installed or
cut/removed, the Arduino gets its power from USB or a power supply
connected to its 2.1mm (center positive) power jack.
The Arduino provides a Vin connection to connect an external power
source that can be from 7V to 12V, remember the diode D1 can not be
connected if you plan to power the Arduino using its Vin.
The Arduino Mega is not rated for voltages higher than 12V. If your board has a 1N4004 diode soldered in Diode D1 (which is the case with
most assembled board), do not apply more than 12V in the 5A connector
of your Ramps, refer to RAMPS 24v for more information.