Correct the code in the UDF.
Function myPrice(myPart As String, myVol As Integer)
Application.Volatile
Dim myCol As Integer
Dim myCavity As Integer
Dim myCycleTime As Integer
myCol = Application.WorksheetFunction.Match(myPart, Range("Item_Name"), 0)
myCavity = Application.WorksheetFunction.Index(Range("Molding_Data"), Application.WorksheetFunction.Match("Cavities", Range("pRows"), 0), myCol)
myCycleTime = Application.WorksheetFunction.Index(Range("Molding_Data"), Application.WorksheetFunction.Match("Cycle Time", Range("pRows"), 0), myCol)
myPrice = myCavity * myCycleTime / myVol
End Function
I was trying to get you to post the code - hard to fix something you can't see...
You need to qualify your Range objects with the correct workbook and worksheet or, preferably, pass the ranges as arguments to the UDF.
Function myPrice(myPart As String, myVol As Integer)
Application.Volatile
Dim myCol As Integer
Dim myCavity As Integer
Dim myCycleTime As Integer
Dim wb As Workbook
Dim ws As Worksheet
Set wb = ThisWorkbook
Set ws = wb.Worksheets("Sheet1")
With ws
myCol = Application.WorksheetFunction.Match(myPart, .Range("Item_Name"), 0)
myCavity = Application.WorksheetFunction.Index(.Range("Molding_Data"), Application.WorksheetFunction.Match("Cavities", .Range("pRows"), 0), myCol)
myCycleTime = Application.WorksheetFunction.Index(.Range("Molding_Data"), Application.WorksheetFunction.Match("Cycle Time", .Range("pRows"), 0), myCol)
End With
myPrice = myCavity * myCycleTime / myVol
End Function