A problem like this could be caused by any number of things, James. Electronically interrogating the on-board computer is a wise first step, as the error codes that will result will possibly lead you straight to the offending component.
In cars like yours with electronic fuel-injection and engine management, there’s an array of sensors that need to send the correct signal to the car’s on-bord brain for everything to function properly. Replacing these sensors one by one until you fix the problem is a very time and cash consuming way of proceeding. Have the car scanned instead and see what fault codes show up.
Meantime, if I had to venture a guess, I’s say the problem sounds ignition related. An engine will often idle properly with no load on it, but when you select a gear, there’s suddenly load applied and, if the ignition system is not spot on, the engine can suddenly do all sorts of crazy things, including dropping cylinders. The other thing that occurs to me is that your battery might be low on charge. Injected engines absolutely do not like a lack of volts.