Well I must say quite an innovative method, did not expect a UDF as such.

The code appears to be operational though.

I have to run for a bit, but will come back and post another solution as well as start some discussion on pros/cons of methods used.