I have also been trying to simulate a similar problem as the case in the PDF file which you have uploaded. However, I am having problems in getting the UDF right for the example. Can you please post the code for the UDF as a reference for the case? It would be very helpful.
Thanks in advance.