vba - VBA自定义函数可以知道公式是作为数组公式输入的吗?

标签 vba excel

是否可以让以下函数根据用户输入公式的方式返回多个值或单个值?

Public Function Test(ByVal flNumber As Double) As Variant
  Dim flResult1 As Double
  Dim sResult2 As String
  Dim bArrayFormula As Boolean

  flResult1 = Round(flNumber / 10 ^ 6, 1)
  sResult2 = "million"

  ' How to know that the formula is entered as an array formula?
  If bArrayFormula Then
    Test = Array(flResult1, sResult2)
  Else
    Test = flResult1 & " " & sResult2
  End If
End Function

最佳答案

只需检查Application.Caller

Public Function SmartFunction() As String
    addy = Application.Caller.Address
    If Range(addy).HasArray Then
        SmartFunction = "Array Formula"
    Else
        SmartFunction = "Normal Formula"
    End If
End Function

关于vba - VBA自定义函数可以知道公式是作为数组公式输入的吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30819127/

相关文章:

vba - 在 Excel 中将 RTF(富文本格式)代码转换为纯文本

python - 为什么 xlrd 读取一个文本格式的数字作为一个 float ?

vba - 在 worksheet_change 事件之后 Excel 超链接跟随宏

vba - 使用宏/vba 将多行从一个工作表复制到另一工作表

excel - 搜索特定的列标题名称,复制列并粘贴以附加到另一个 wookbooksheet

没有 Pandas 的Python解码excel表

excel - 我正在尝试复制和重命名工作表,但出现下标超出范围错误

vba - 如何在 VBA 中打开并定义两个 Excel 文件?

正则表达式在某些文本之前提取数据

vba - 删除特定页面的所有制表符