我编写了一个函数interpolate_part_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