Excel宏可在按下Enter键时修改单元格 [英] Excel macro to modify cells when enter is pressed

查看:52
本文介绍了Excel宏可在按下Enter键时修改单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找有关宏的帮助,以根据在另一个单元格中输入的内容来减少单元格的值.我有5列,我将在其中输入值以及已经有数据的2列.当我在5列之一中输入数字时,我希望弹出一个显示"Blah Blah"的窗口,如果单击是",我希望将该单元格中的值从另一个需要减去的单元格中减去查找了其他两列中的信息.

I'm looking for some help on a macro to reduce a cells value based on what was entered in another cell. I have 5 columns that I will be entering values into along with 2 columns that already have data. When I enter a number into one of the 5 columns, I want a window to pup up that says "Blah Blah", if I click yes, I would like the value in that cell to be subtracted from another cell that will need to be looked up with information from those other two columns.

工作表1:

    A   B   C   D   E   F   G
1                       5   10

表格2:

    A   B   C   D   E   F   G
1       2   4   6   8   10  12
2   2
3   4
4   5

因此,如果我要在工作表1的A1中键入"250",则宏会将工作表2的单元格F4中的值减少250,因为这是工作表1中的5、10的值.?根据我在其中键入值的列将进行更多的过滤,以后我应该可以对其进行修改.

So if I were to type '250' into A1 on sheet 1, the macro would reduce the value in cell F4 in sheet 2 by 250 because that's the value for the 5, 10 from sheet 1. Is something like this possible? There would be more filtering based on which column I type the values into, I should be able to modify that in later.

推荐答案

首先,请确保您无法使用公式完成足够好的解决方案,因为编写宏将需要更多工作.

First, make sure that you can't accomplish a good enough solution with formulas, because writing a macro will be more work.

如果您仍然需要一个宏,则需要为有关工作表的 Worksheet_Change 事件编写一个函数.此链接将向您展示如何执行此操作.

If you still need a macro, you will want to write a function around the Worksheet_Change event for the worksheet in question. This link will show you how to do this.

在处理 Worksheet_Change 事件时,请注意不要生成另一个 Worksheet_Change .由于对工作表更改的部分响应将是另一个更改,因此在代码前先添加 Application.EnableEvents = False ,然后在其后添加 Application.EnableEvents = True .

Be careful not to generate another Worksheet_Change while handling Worksheet_Change event. Since part of your response to the worksheet change is going to be another change, precede your code with Application.EnableEvents = False and follow it with Application.EnableEvents = True.

这篇关于Excel宏可在按下Enter键时修改单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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