One to many matching is possible (though computationally intense) using Solver. You will find a number of PAQ in the Excel TA that use this approach, such as http:/Q_22017330.html Although that PAQ uses worksheet formulas, it can be automated using VBA code. It will also do the one to one matching at the same time.

Many to many matching is enormously more computationally intense using Solver. I'm not sure the free version of Solver is even capable of doing it with a reasonable database. There are much more powerful versions of Solver available for purchase from its developer Frontline Systems--see http://www.solver.com/cata

You requested to first match many to many, then proceed to one to many, and last with one to one. I suggest that the opposite order is more likely to get you an answer.