vba Excel中的数组乘法

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22598419/
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-12 02:27:28  来源:igfitidea点击:

Array multiplication in Excel

arraysexcelexcel-vbamatrix-multiplicationvba

提问by Brent Ferrier

In my excel document I have two sheets. The first is a data set and the second is a matrix of the relationship between two of the variables in my data set. Each possibility of the variable is a column in my matrix. I'm trying to get the sum of the products of the elements in two different arrays. Right now I'm using the formula {=SUM(N3:N20 * F3:F20)}and manually changing the columns each time. But my data set is over 800 items...

在我的 excel 文档中,我有两张纸。第一个是数据集,第二个是我的数据集中两个变量之间关系的矩阵。变量的每种可能性都是我矩阵中的一列。我试图获得两个不同数组中元素的乘积之和。现在我正在使用公式{=SUM(N3:N20 * F3:F20)}并每次手动更改列。但是我的数据集超过 800 项...

Ideally I'd like to know how to write a program that reads the value of the variable in my dataset looks up the correct columns in the matrix, multiplies them together, sums the products, and puts the result in the correct place in my data set. However, just knowing the result for all the possible combinations of columns would also save me alot of time. Its an 18x18 matrix. Thanks for any feedback!

理想情况下,我想知道如何编写一个程序来读取数据集中变量的值,查找矩阵中的正确列,将它们相乘,对乘积求和,并将结果放在我的数据中的正确位置放。然而,仅仅知道所有可能的列组合的结果也会为我节省大量时间。它是一个 18x18 的矩阵。感谢您的任何反馈!

采纳答案by asif

Your question is a little bit ambiguous butas far as i understand your question you want to multiply different sets of two columns in the same sheet and put their result into the next sheet, is it so? if so, please post images of your work (all sheets). Your answer is possible even in Excel only without any vba code, thanks. you can also use =SUMPRODUCT(N3:N20,F3:F20)for your formula instead of {=SUM(N3:N20 * F3:F20)}

您的问题有点模棱两可,据我了解您的问题,您想将同一工作表中两列的不同组相乘并将其结果放入下一张工作表中,是吗?如果是这样,请张贴images of your work (all sheets)。即使在没有任何 vba 代码的 Excel 中,您的答案也是可能的,谢谢。你也可以用=SUMPRODUCT(N3:N20,F3:F20)你的公式代替 {=SUM(N3:N20 * F3:F20)}