對,這是確實的那些情況下一個,其中僅一個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 安德烈亞斯