是否有公式或宏可以在另一个单元格中找到对单元格的引用?例如:
A | B | C
------------------
1| 1 | 2 | =A1+B1
是否有将 aC1
作为输入并返回的公式=1+2
?
您可以尝试使用此用户定义函数将公式中使用的单元格引用转换为其根据您的要求的值。
将以下函数放在像 Module1 这样的标准模块上。
Function CellRefereceToValue(ByVal rng As Range) As String
Dim re As Object, Matches As Object, Match As Object
Dim str As String
Set re = CreateObject("VBScript.RegExp")
With re
.Global = True
.Pattern = "[A-Z]+\d+"
End With
str = rng.Formula
If re.test(str) Then
Set Matches = re.Execute(str)
For Each Match In Matches
str = Replace(str, Match, Range(Match).Value)
Next Match
End If
CellRefereceToValue = str
End Function
然后假设你的公式在 C2 中,如下图所示,在工作表上使用这个函数,如下所示......
=CellRefereceToValue(C2)
在下图中,Excel 公式放在 C 列中,公式文本放在 D 列中以显示 C 列中使用的公式,然后在 E 列中,您可以看到 UDF 替换了 C 列中公式中使用的所有单元格引用与它们对应的值。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句