对,这是确实的那些情况下一个,其中仅一个UDF(用户定义的公式)的伎俩。这里有一个可能的功能(不太复杂);你当然可以在你的UDF中添加更多你需要的处理。
Function FormulaText(cell As Range, _
Optional default_value As Variant)
' Returns the formula of the top leftmost cell in range as text
' default_value Value to return, if cell is empty
Set cell = cell.Resize(1, 1)
If cell.Formula = "" And Not IsMissing(default_value) Then
FormulaText = default_value
Else
FormulaText = cell.Formula
' If using a non-Englisch Version of Excel, cell.FormulaLocal
' returns the Formula in the localized format
' instead of e.g.
' =SUM(C7, C9) in my case it would return
' =SUMME(C7;C9)
End If
End Function
打开Visual Basic编辑器(Alt + F11),创建一个新模块并将代码粘贴到编辑区域。
用EXCEL
=FormulaText(A1, "No formula") with default value if referenced cell is empty
=FormulaText(A1) without default value
=FormulaText(A1:B3) return only the formula from A1
HTH 安德烈亚斯