K3是欲查算的值(num1)
B30:B54是索引列(rng1)
H30:H54是数据列(rng2)
比如:
num1=25
rng1 rng2
1 20
2 50
3 30
4 10
那么它会选2对应的值50和3对应的值30进行线形插值
结果应该是50+(30-50)(25-2)/(3-2)=40
而如果num1的值在索引列(rng1)存在的话,直接返回数据列(rng2)中与之相对应的值
具体函数如下:
-------------------------------------------
Function zxnc(num1, rng1, rng2)
'直线内插数值
'num1:欲查算的x值
'Dim cc As Single
'Dim aa1 As Single
cc = num1
aa1 = ApplicationLookup(cc, rng1)
row1 = ApplicationMatch(aa1, rng1, 0)
If cc = aa1 Then
row2 = row1
Else
row2 = row1 + 1
End If
x1 = ApplicationIndex(rng1, row1)
x2 = ApplicationIndex(rng1, row2)
aa2 = ApplicationLookup(x1, rng1, rng2)
aa3 = ApplicationLookup(x2, rng1, rng2)
If cc = aa1 Then
xs = 0
Else
xs = (cc - aa1) / (x2 - x1)
End If
zxnc = aa2 + (aa3 - aa2) xs
End Function
ApplicationLookup()
引用工作本函数以Application开头
工作本函数就是EXCEL工作本-单元格里常用的那些如
SUM,LEFT,RIGHT,COUNT等函数
http://wwwdoc88com/p-2983968985812html这是下载的地址,百度文库上也有http://wenkubaiducom/linkurl=aPY3HBlLzoYpyG2_jhr5fobv3osr7qMpZE39Vw3ivJSYYYUEf6_yyoa3Jz4dRRoBwUFlF8Td0mWkIz8ofGlX2pOo1PK9cWANAX5VWjh4Pa3
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)