I have a large excel of purchase orders where i need to add all the quantities of unique part numbers. I am trying to search the entire excel file, and add the quantities if they are a specific part number.
Example:
Part Number QTY
364 7
364 11
373 6
373 8
373 54
334 8
334 2
I want to be able to create a function with the part number and all data as an input that spits out the total for selected part number. For example, if i wanted to find the total quantity of 364 i would type into excel:
QtyPerPN(364, A2:B8) would return 18.
How do i make the QtyPerPN() function correctly?
Function QtyPerPN(PartNumber, PN_QTYRange() As Variant)
Dim TotalQty, counter
TotalQty = 0
counter = 0
Dim i As Long
i = 0
Do While counter < 15
'15 is just for testing on small set amount of data
counter = counter + 1
If PartNumber = PN_QTYRange(i) Then
TotalQty = TotalQty + PN_QTYRange(i, i)
i = i + 1
End If
Loop
QtyPerPN = TotalQty
End Function
Jonathan Crane is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.