gpt4 book ai didi

excel - 从 Excel 公式中提取参数或字符串 - Excel 2003

转载 作者:行者123 更新时间:2023-12-04 20:20:29 26 4
gpt4 key购买 nike

我需要对单元格公式而不是单元格内容执行 Mid 或 Find。

如果我的单元格公式是:

=[功能](Arg1, Arg2, Arg3)

我需要能够将 Arg2 提取到另一个单元格。

如果不使用 VBA 或特殊的 Excel 加载项,这可能吗?

我试过使用单元格,但没有选项可以返回单元格包含的公式,如果我可以将该公式作为字符串分解到另一个单元格,我将能够使用 Mid 和 Find 等。

有任何想法吗?

干杯

最佳答案

是的,这确实是其中一种情况,只有 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

高温高压
安德烈亚斯

关于excel - 从 Excel 公式中提取参数或字符串 - Excel 2003,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4105290/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com