公式的实时执行

发布于 2024-08-12 03:23:43 字数 130 浏览 1 评论 0原文

我们可以在不将光标移出单元格的情况下执行公式吗?将数据输入到输入单元格后,我们可以按 Enter 键,也可以从该单元格移出,然后执行与之相关的任何公式。有什么方法可以在输入输入本身时我们可以在 Excel 中看到输出结果吗?请帮助我找到这个选项。

can we execute a formula without moving cursor from the cell? After giving data in to Input cell either we press enter or we move from that cell and then any formula related to that gets executed. Is there any way that while entering input itself we can see the result in output in excel?Please help me in finding this option.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

苏佲洛 2024-08-19 03:23:43

我不相信当单元格的“编辑器”拥有焦点和控制权时,代码不可能执行。例如,在编辑公式时尝试在 Excel 中执行其他操作。我相信单元格必须在代码执行之前完成保存其值或公式。

您可以使用公式“监听”单元格何时更新,但这有点复杂。一旦更新,它可能会迫使您返回原始单元格。下面介绍了如何编写一些代码来“侦听”单元格值何时发生变化。在以下示例中:

  • 我将 Cell I1 的值记录到 strValue
  • 然后,我运行一个循环,只要单元格 I1 的值没有更改,该循环就会保持运行。
  • DoEvents 命令将控制权释放回处理器,这样您就可以在 Excel 运行时使用它。
  • 一旦单元格I1的值发生变化,While语句将为假并且循环将退出。
  • 循环退出后,会弹出一个消息框,告诉您值已更改,然后再次选择原始单元格。

'

Sub testChange()
Dim strValue As String

strValue = Range("I1").Value

Do While strValue = Range("I1").Value
    DoEvents
Loop

MsgBox "The value changed!"
Range("I1").Activate
End Sub

也许,如果您只是想在每次值更改时将控制权返回到原始单元格,则可以使用上面的行而不使用消息框,并在方法执行后返回到循环。请记住,如果您这样做,您可能需要找到另一种方法来退出代码。

为什么要让它在单元格内执行?您的任务的最终目的是什么?

I don't believe it's possible for code to execute while the "editor" of a cell has focus and control. For example, try doing something else in Excel while you are editing a formula. I believe that the cell has to finish saving its value or formula before code can execute.

You can have a formula "listen" for when a cell is updated, but this is a little bit complicated. It could then force you back into the original cell once it is updated. Here's how you can write some code to "listen" for when a value of a cell changes. In the following example:

  • I record the value of Cell I1 to strValue.
  • Then I run a loop that stays running as long as the value of cell I1 has not changed.
  • The DoEvents command releases control back to the processor, which is what allows you to work in Excel while this is running.
  • Once the value of cell I1 changes, the While statement will be false and the loop will exit.
  • After the loop exits, a message box pops up that tells you the value changed and then the original cell is selected again.

'

Sub testChange()
Dim strValue As String

strValue = Range("I1").Value

Do While strValue = Range("I1").Value
    DoEvents
Loop

MsgBox "The value changed!"
Range("I1").Activate
End Sub

Perhaps if you simply wanted to return control back to the original cell every time the value changed, you could use the line above without the message box and return to the loop once your method executes. Keep in mind that you might have to figure out another way to exit your code if you do that.

Why do you want to have it execute from within the cell? What is the end purpose of your task?

涙—继续流 2024-08-19 03:23:43

按 F9 进行重新计算,无需离开输入单元格。这适用于 Excel 2007。我不确定早期版本是否有效。

Press F9 to do a re-calc without moving from the input cell. This works in Excel 2007. I'm not sure about earlier versions.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文