从Excel公式 – Excel 2003中提取参数或string
我需要在单元格公式上做一个Mid或Find,而不是单元格内容。
如果我的单元格公式是:
= [Func](Arg1,Arg2,Arg3)
我需要能够提取说Arg2到另一个单元格。
这可能不使用VBA或特殊的Excel加载项?
我试过使用单元格,但没有选项可以返回单元格包含的公式,如果我可以将该公式以string的forms分解到另一个单元格,则可以使用Mid和Find等。
有任何想法吗?
干杯
是的,这确实是其中的一种情况,只有一个UDF(用户定义的公式)才能做到这一点。 这里有一个可能的function(不太复杂); 你当然可以添加更多你需要的处理到这个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 eg ' =SUM(C7, C9) in my case it would return ' =SUMME(C7;C9) End If End Function
打开Visual Basic编辑器(Alt + F11),创build一个新模块并将代码粘贴到编辑区域。
在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 Andreas