Arduino Mega code on Arduino Nano

Hi,
Thank you for the answer.
You are right , memory is the limitation; below is the error output when compling

##############
Sketch uses 40550 bytes (131%) of program storage space. Maximum is 30720 bytes.
Global variables use 2044 bytes (99%) of dynamic memory, leaving 4 bytes for local variables. Maximum is 2048 bytes.
Sketch too big; see https://support.arduino.cc/hc/en-us/articles/360013825179 for tips on reducing it.
text section exceeds available space in board

Compilation error: text section exceeds available space in board
#######

Thanks