vba 如何根据excel中的其他单元格值更新单元格值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13807632/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 18:45:27  来源:igfitidea点击:

How to update a cell value based on other cell values in excel

excelexcel-vbavba

提问by Narry

In the attached spreadsheet ( Sales Analysis Report), I would like to update column H value automatically by using below fields. enter image description here

在附加的电子表格(销售分析报告)中,我想使用以下字段自动更新列 H 值。 在此处输入图片说明

enter image description here

在此处输入图片说明

enter image description hereSales:D column, Sales:H column, Payments Receieved:D columnand Payments Receieved:H column

在此处输入图片说明Sales:D 列Sales:H 列Payments Receieved:D 列Payments Receieved:H 列

Can you please guide me how we can achieve this either through macro (VBA code) (or) we can do this in a simple formula as well.

您能否指导我如何通过宏(VBA 代码)(或)我们也可以用一个简单的公式来实现这一点。

I have highlighted all the cells which are required for this logic in color.

我已经用颜色突出显示了此逻辑所需的所有单元格。

Thanks in advance for your time and appreciated your help.

提前感谢您的时间并感谢您的帮助。

Regards, Narry

问候,纳里

回答by Scott Holtzman

No VBA needed here, Narry.

这里不需要 VBA,纳里。

Enter this formula in cell H1of Customer Information tab:

H1客户信息选项卡的单元格中输入此公式:

=SUMIF(Sales!D:D,D1,Sales!H:H)-SUMIF('Payments Recieved'!D:D,D1,'Payments Recieved'!H:H)

=SUMIF(Sales!D:D,D1,Sales!H:H)-SUMIF('Payments Recieved'!D:D,D1,'Payments Recieved'!H:H)

Then drag down to fit the other rows.

然后向下拖动以适合其他行。

You can easily google 'vlookup' or look in Excel Help to find out more about what it does.

您可以轻松地使用谷歌搜索“vlookup”或查看 Excel 帮助以了解有关其功能的更多信息。

回答by Bryan Glazer

I'm assuming you want Column H to be Col. G and Col. F multiplied. If this is correct then a simple formula will work.

我假设您希望 H 列是 G 列和 F 列相乘。如果这是正确的,那么一个简单的公式将起作用。

In H1 type =F1 * G1

H1型 =F1 * G1

Copy this cell. Select the rest of the cells in H that need the formula, and paste.

复制此单元格。选择 H 中需要公式的其余单元格,然后粘贴。