Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add arrays?

Tags:

arrays

excel

vba

I have the following problem in Excel while calculating through a loop: I need a variable (Destination Variable) that sequentially stores the results produced after each loop has been completed (avoiding the use of circular references) that would look like this:

'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

After each loop, I'd need the macro to perform the following code:

range("destination").value = range("destination").value + range("origin").value 

So that the destination variable would look like this after the current loop:

Destination Variable
      2 3 5
      3 4 5
      3 3 4

However, Excel does not allow me to perform the previous function.
Does anyone have an answer how this could be solved?

like image 288
user3617237 Avatar asked Jan 11 '23 15:01

user3617237


1 Answers

Quite easy. I did this by recording as macro and tidying.

Sub Macro1()            
    Range("origin").Copy
    Range("destination").PasteSpecial Paste:=xlPasteAll, Operation:=xlAdd, _
        SkipBlanks:=False, Transpose:=False
    Application.CutCopyMode = False
End Sub
like image 67
S Meaden Avatar answered Jan 13 '23 05:01

S Meaden