如何返回单元格信息
本来想用Cell()函数解决问题的,不过试了多次没能成功,给出一个算定义函数的解决思路,供参考:
“Alt+F11”进入VBE --》 “插入”--》 “模块”,
复制以下代码:
Option Explicit
Function findadd(rngSource As Range, varValue As Variant) As String
Application。 Volatile '标志此自定义函数为易失性函数
Dim c As Range
With rngSource
Set c = 。Find(varValue, LookIn:=xlValues) '在rngSorce中查找...全部
本来想用Cell()函数解决问题的,不过试了多次没能成功,给出一个算定义函数的解决思路,供参考:
“Alt+F11”进入VBE --》 “插入”--》 “模块”,
复制以下代码:
Option Explicit
Function findadd(rngSource As Range, varValue As Variant) As String
Application。
Volatile '标志此自定义函数为易失性函数
Dim c As Range
With rngSource
Set c = 。Find(varValue, LookIn:=xlValues) '在rngSorce中查找varValue
If Not c Is Nothing Then
findadd = c。
Address '找到第一个匹配的值就返回其所在的单元格地址
Else
findadd = "#N/A" '没有找到就返回“#N/A”
End If
End With
End Function
然后到工作表中像使用普通函数一样:
=findadd(A1:A31,B1)
其中“A1:A31”是要查找的数据区域,要查找的值是“B1”
简单吧:)。
收起