通过循环计算时,我在 Excel 中遇到以下问题: 我需要一个变量(目标变量)来顺序存储每个循环完成后产生的结果(避免使用循环引用),如下所示:
'Let's call it "origin" variable in the worksheet
Origin Variable (50 x 50 array)
1 2 4
2 3 4
2 2 3
'Let's call it "destination" variable in the worksheet
Destination Variable (50 x 50 array)
1 1 1
1 1 1
1 1 1
每次循环之后,我需要宏来执行以下代码:
range("destination").value = range("destination").value + range("origin").value
这样目标变量在当前循环之后将如下所示:
Destination Variable
2 3 5
3 4 5
3 3 4
但是,Excel 不允许我执行前面的功能。
有谁知道如何解决这个问题吗?
最佳答案
很简单。我通过录制为宏并整理来做到这一点。
Sub Macro1()
Range("origin").Copy
Range("destination").PasteSpecial Paste:=xlPasteAll, Operation:=xlAdd, _
SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
End Sub
关于arrays - 如何添加数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23547033/