vba - 采用动态数组并返回动态数组的 VBA 函数
问题描述
我有一个在 A1:A100 中有重复的数字列表。使用 Excel 新的动态数组函数,我们可以在 Cell D1 中写入=UNIQUE(A1:A100)
以获得唯一列表。
然后,我们可以在单元格 E1=D1#+100
中写入,以根据 D 列的值获取动态列表。
现在,我想编写一个 VBA 函数MYFUN
来实现相同的目的,这样我们就可以=MYFUN(D1#)
在单元格 F1 中编写以获得与 E 列相同的值。
有人知道怎么写吗?
解决方案
不是 100% 清楚你想要做什么 - 似乎缺少一些东西。
但是,当您=MYFUN(D1#)
在 F1 中输入公式时,这将返回 E 列中的内容。
Function MYFUN(rng As Range) As Variant
MYFUN = Evaluate(rng.Address & "+100")
End Function
这是一个不使用的替代方案Evaluate
。
Function MYFUN(rng As Range) As Variant
Dim arr As Variant
Dim idx As Long
ReDim arr(1 To rng.Rows.Count, 1 To 1)
For idx = LBound(arr, 1) To UBound(arr, 1)
arr(idx, 1) = rng.Cells(idx, 1) + 100
Next idx
MYFUN = arr
End Function
推荐阅读
- firebase - 在 Flutter 中将文档保存到 Firebase 云数据库时出错
- wordpress - 自定义 woocommerce 产品名称挂钩
- angular - Ionic Angular Firestore 不在视图中显示单个文档数据
- html - 如何让子菜单留在基本菜单的右侧?
- php - PHP比较两个数组并过滤数组具有特定值
- python - 上传pypi错误:HTTPError:403客户端错误:身份验证信息无效或不存在
- r - 使用 Rbind 将元素添加到 R 中的数据框
- php - Laravel 6:作曲家更新后,身份验证登录出现空白屏幕。没有解决方案有帮助,即使是还原生产副本或新项目
- android - Android Jetpack BottomNavigationView如何应用自定义Fragment Transition
- php - 使用 Laravel 在视图中插入嵌套的 foreach 时,Bootstrap/Tempalte 不起作用