
我想知道是否有任何公式可以让我这样做:我希望Excel能够阅读H5中的任何内容(即12-52),并检查以下条件:
If H5 equals H4 then take whatever is in N4 and insert it into I5
If H5 equals O4 then take whatever is in U4 and insert it into I5
If H5 equals V4 then take whatever is in AB4 and insert it into I5
If H5 equals AC4 then take whatever is in AI4 and insert it into I5 如您所见,H5等于AC4,因此从AI4单元中获取值80,并将其插入I5单元格中,并放弃所有其他条件。
发布于 2015-03-27 17:50:39
用I5编写跟随函数
=if(h5=h4,n4,if(h5=o4,u4,if(h5=v4,ab4,if(h5=ac4,ai4,"error"))))如果它不承认,那么试着用iif替换If
实际上,我将所期望的值放在take部件中,并为下一步的"if“函数使用value部分,直到最后一部分您还没有声明应该使用什么值时,我冒昧地将其视为错误。
更新:获取最大值的函数
=max(if(h5=h4,n4,-10000),if(h5=v4,ab4,-10000),if(h5=o4,u4,-10000),if(h5=ac4,ai4,-10000))在这里我推测-10000是你永远不会得到的价值.我不能在这里使用错误字符串,因为max必须处理它。
根据我对您的需求的分析,这里的宏代码没有问题:
Option Explicit
Function mymax() As String
Dim value As String
Dim r, c, pos
value = -1000
c = ActiveCell.Column-6
r = ActiveCell.Row
For i = c To 299
pos = 1 + i * 7
If Cells(r, c) = Cells(r - 1, pos) Then
If value < Cells(r - 1, pos+6) Then
value = Cells(r - 1, pos+6)
End If
Next
If value = -1000 Then
max = "ERROR"
Else
max = value
End If
End Function您将此函数称为宏生命任何其他excel函数:
=mymax()发布于 2015-03-27 17:51:03
=IF(H5=H4,N4,IF(H5=O4,U4,IF(H5=V4,AB4,IF(H5=AC4,AI4,0)
https://stackoverflow.com/questions/29306896
复制相似问题