use*_*237 4 arrays excel vba excel-vba
通过循环计算时,我在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
Run Code Online (Sandbox Code Playgroud)
在每个循环之后,我需要宏来执行以下代码:
range("destination").value = range("destination").value + range("origin").value
Run Code Online (Sandbox Code Playgroud)
这样在当前循环之后目标变量看起来像这样:
Destination Variable
2 3 5
3 4 5
3 3 4
Run Code Online (Sandbox Code Playgroud)
但是,Excel不允许我执行上一个功能.
有没有人有答案如何解决这个问题?
很容易.我通过录制宏观和整理来做到这一点.
Sub Macro1()
Range("origin").Copy
Range("destination").PasteSpecial Paste:=xlPasteAll, Operation:=xlAdd, _
SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
End Sub
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6639 次 |
| 最近记录: |