如何从VBA写入单元格 [英] how to write to a cell from VBA

查看:294
本文介绍了如何从VBA写入单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

即使对于VBA新手来说,这似乎是一个愚蠢的问题,但是我无法弄清楚如何在VBA中写入单元格...我在Module1中有一个如下所示的功能:

 函数Foo(bar As Boolean)
范围(A1)。Value = 1
Foo = ...
结束函数

然后说我将单元格A2的公式设置为:

  = Foo(true)

如果我取出范围设置行,则调用本身就可以工作,在这种情况下,将调用单元格设置为foo值。但是我想这样做最终会一次写出一吨的单元格,而不是每个单元格都有一个不同的函数调用。我做错了什么?






如果这段代码应该正常工作...在Excel 2007中有设置这可能是阻止编辑单元格,或类似的细节?

解决方案

根据此页面,Excel用户定义的函数不可能更改Workbook的其他部分。看来您可能需要尝试其他方式。


seems like a dumb question even for a VBA newbie, but I can't figure out how to write to a cell in VBA... I have a function in "Module1" that looks like this:

Function Foo(bar As Boolean)
  Range("A1").Value = 1
  Foo = ...
End Function

Then say I set Cell A2's formula to:

=Foo(true)

The call itself works if I take out the range setting line... in that case setting the calling cell to the foo value. But I'd like this to eventually write a ton of cells at once rather than have a different function call for each cell. What am I doing wrong???


If this code should work as is... are there settings in Excel 2007 that might be blocking editing a cell, or something like that?

解决方案

According to this page, it's not possible for an Excel user defined function to alter other parts of the Workbook. Looks like you may have to try another way.

这篇关于如何从VBA写入单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆