Just noticed the post with FIFO in title. I haven't looked at this for 2 yrs. Suggest you work with the zip from post #14. You'll have to work out the logic for your weighted average. You could post a description of how you will calculate "weighted average" in plain English and perhaps others will offer advice.
Good luck. Glad you liked the sample.