I could use some help fixing my broken code, there are some missing pieces that I'm not quite sure how to code. I try and explain what I am trying to accomplish in my code given below.
I am using two named ranges ([OIB_STD_OPS] & [Product_Line_To_Dept_Num]). I defined these using Name Manager. [OIB_STD_OPS] has duplicate data. I do not want these added line after line, but I do want the number captured in column D (See image below).
One thing to note is that the array [OIB_STD_OPS] will not always be sorted by department sequence number.
Capture.JPG
Sub Quick_Ref()
Dim i
Dim j
Dim k 'Selected Department
Dim d As Range 'Number of departments
Dim rd 'Number of rows with selected departments in named range [OIB_STD_OPS] (Could have multiple departments in product line)
d = Range("[Product_Line_To_Dept_Num]").Rows.Count
rd = ??? 'Number of rows with selected departments in named range [OIB_STD_OPS] (Could have multiple departments in product line)
For j = 1 To d
k = WorksheetFunction.HLookup(Range("B1"), [Product_Line_To_Dept_Num], j + 1, 0)
For i = 1 To rd
Range("Cells(3+i, 1)") = ??? '"Code" with selected "variable k" department
Range("Cells(3+i, 2)") = WorksheetFunction.VLookup(Range("Cells(3+i, 1)"), [OIB_STD_OPS], 2, 0)
Range("Cells(3+i, 3)") = WorksheetFunction.VLookup(Range("Cells(3+i, 1)"), [OIB_STD_OPS], 3, 0)
Range("Cells(3+i, 4)") = ??? '# of rows "Code:(Cells(3+i, 1)" appears in [OIB_STD_OPS]
Next i
Next j
End Sub
'--------------------------
Sub Delete_Ref()
???
End Sub