如何使用函数将单元格值插入另一个单元格?

在这里输入图像说明

我想知道是否有任何公式可以让我做:我想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单元并丢弃其他所有条件。

在I5中写下面的函数

 =if(h5=h4,n4,if(h5=o4,u4,if(h5=v4,ab4,if(h5=ac4,ai4,"error")))) 

如果它不能识别,然后尝试用iifreplace

实际上,我将所需的值放在truepart中,并使用falsepart作为下一个“if”函数,直到最后一部分还没有声明什么值应该去,我冒昧地把它作为ERROR

更新:函数来获取最大值

 =max(if(h5=h4,n4,-10000),if(h5=v4,ab4,-10000),if(h5=o4,u4,-10000),if(h5=ac4,ai4,-10000)) 

在这里我推测-10000是你永远不会收到的价值…我不能把错误string作为最大的工作。

macros代码没有问题,根据我的分析你的要求:

 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 

你调用这个函数macros命令任何其他的Excel函数:

 =mymax() 

= IF(H5 = H4,N4,IF(H5 = O4,U4,IF(H5 = V4,AB4,IF(H5 = AC4,AI4,0))))