excel - 将函数参数作为公式传递
问题描述
这是我的 VBA 脚本的代码:
Function custom_if_formula(condition)
MsgBox(condition)
End Function
我将公式粘贴到任何单元格:
=custom_if_formula(B1="something")
MsgBox 中的结果是:TRUE
或FALSE
。结果是否有可能进入 MsgBox B1="something"
?
我想要实现的伪代码:
Function custom_if_formula(condition)
condition = condition.formula 'any method which take a literal string
MsgBox(condition)
End Function
PS 我的目标是实现我自己的 IFS 函数,其行为与 Excel 2016 中的行为相同。我只是好奇它是否可能。这就是为什么我不想将字符串作为参数传递。
解决方案
好的,我找到了一种方法:
Function custom_if_formula(condition)
cell_formula = Range(Application.Caller.Address).Formula 'I get an adress of a cell which call an UDF, and then take all string it contains
arg = Mid(cell_formula, 12, 100)
MsgBox(arg)
End Function
推荐阅读
- python - 如何允许最后一个 resnet 块可训练?
- python-3.x - pymongo 是否支持 json 模式验证?
- node.js - 无法在节点中创建新项目
- angular - 如何添加服务提供商
- php - 匹配 unicode 块或索引范围的正则表达式
- drools - Drools 关于 memberOf 和 contains 相等性的问题
- google-bigquery - BigQuery 在分组 id 时获取最新记录,按日期排序
- arrays - 来自 Json 的 React-Name 数组,以变量为键
- java - getActualMaximum 函数返回 kotlin 中不存在的值
- html - 菜单中心如何正确(СSS)