代码之家  ›  专栏  ›  技术社区  ›  BIBD

如何将函数结果返回Excel中的单元格?

  •  3
  • BIBD  · 技术社区  · 17 年前

    假设我的Excel工作表中有一个函数:

    Public Function foo(bar As Integer) as integer
        foo = 42
    End Function
    

    foo 回到我床单上的一间牢房?我试过了 "=foo(10)" "#NAME?"

    =[filename]!foo(10) and [sheetname]!foo(10) 没有变化。

    4 回复  |  直到 17 年前
        1
  •  5
  •   BIBD    10 年前

    试着按照指示去做 here 确保你做的每件事都是正确的,特别是关于放在哪里。( Insert->Module )

    我可以确认打开VBA编辑器,使用 插入->单元

    Function TimesTwo(Value As Integer)
        TimesTwo = Value * 2
    End Function
    

    在床单上 "=TimesTwo(100)" 进了一个牢房给了我 200

        2
  •  3
  •   anorm    17 年前

    将函数放入一个新的单独模块(Insert->模块),然后在单元格公式中使用=foo(10)来调用它。

        3
  •  1
  •   JeffK    17 年前

        4
  •  -1
  •   chilltemp    17 年前

    =PERSONAL.XLS!foo(10)
    
    推荐文章