Apple Hardware Test error 4MEM/9/40... not fixed by replacing memory modules
iMac (27-inch late 2012), 3.4GHz, 32Gb RAM, macOS Sierra 10.12.6
iMac was shutting down unexpectedly and ungracefully. To restart, had to disconnect iMac from mains power for a few seconds then plug back in. Sometimes had to leave disconnected over night. Could no longer upgrade OS because iMac would always crash. (Thank god for Time Machine backup!)
So I ran Apple Hardware Test and got an error 4MEM/9/40000000: 0x80822d90. Searched the Internet and most forums say that this error means a faulty memory module.
So I replaced the memory, all 4 modules.
Then ran the Apple Hardware Test again, but still the same error: 4MEM/9/40000000. Has anyone had this experience and if so what did you do you to fix?
Many thanks for any advice.