I want to put an Excel value according to the quantity into a cell

This thread is a duplicate of I want to put Cell an Excel value into a cell based on quantity.
The final solution is available on the linked post.