Function VBA函数在不应该返回相同结果时返回相同结果?

Function VBA函数在不应该返回相同结果时返回相同结果?,function,vba,row,Function,Vba,Row,我编写了一个函数interpolate\u part\u size,它不会重新计算,除非我在Excel单元格中单击并按Enter键,然后输入正确的结果。该函数的目的是插入一个值,将活动单元格的当前行与参考行进行比较 我已经尝试了Application.Volatile,但是对于同一个参数,它在每一行上都返回相同的结果,这是不正确的。使用F9重新计算也不起作用 有什么建议吗 Function interpolate_part_size(pp) As Double '--- Subroutine t

我编写了一个函数
interpolate\u part\u size
,它不会重新计算,除非我在Excel单元格中单击并按Enter键,然后输入正确的结果。该函数的目的是插入一个值,将活动单元格的当前行与参考行进行比较

我已经尝试了
Application.Volatile
,但是对于同一个参数,它在每一行上都返回相同的结果,这是不正确的。使用F9重新计算也不起作用

有什么建议吗

Function interpolate_part_size(pp) As Double
'--- Subroutine to interpolate size

Dim part_size_high As Double
Dim part_size_low As Double
Dim pp_high As Double
Dim pp_low As Double
Dim low_index As Integer
Dim high_index As Integer
Dim current_row As Integer

With Application.WorksheetFunction

current_row = ActiveCell.Row
' match on the range of cells in the current row

high_index = .Match(pp, Worksheets("DATA").Range(Cells(current_row, 4), Cells(current_row, 29)), -1)
low_index = high_index + 1

pp_high = .Index(Worksheets("DATA").Range(Cells(current_row, 4), Cells(current_row, 29)), 1, high_index)
pp_low = .Index(Worksheets("DATA").Range(Cells(current_row, 4), Cells(current_row, 29)), 1, low_index)
part_size_high = .Index(Worksheets("DATA").Range("PSD"), 1, high_index)
part_size_low = .Index(Worksheets("DATA").Range("PSD"), 1, low_index)

End With

If pp_high = pp_low Then
    interpolate_part_size = part_size_low
    Else:
    interpolate_part_size = (pp - pp_low) / (pp_high - pp_low) * (part_size_high - part_size_low) + part_size_low
End If

End Function

你能提供一些示例excel文件供我使用吗?有一个类似的问题。它有什么有用的想法吗?