One way:
Public Sub Test()
Dim vArr As Variant
Dim i As Long
Dim j As Long
Dim myX As Long
Dim myY As Long
Dim nIndex As Long
i = 10
j = 10
ReDim vArr(1 To (2 * i + 1) * (2 * j + 1), 1 To 3)
For myX = -i To i
For myY = -j To j
nIndex = nIndex + 1
vArr(nIndex, 1) = myX
vArr(nIndex, 2) = myY
vArr(nIndex, 3) = myX + myY
Next myY
Next myX
ActiveCell.Resize(UBound(vArr, 1), 3).Value = vArr
End Sub
In article om,
"nenad" wrote:
Here is a type of code that I am using now. myX, myY and myZ are
filled 'by force' down to rows and is extremely slow. How to make a
code to insert these values into an array and then transfer the
contents of the array to the range?
Code:
Sub Test()
i = 10
j = 10
For myX = -i To i
For myY = -j To j
myZ = i + j
ActiveCell.Value = myX
ActiveCell.Offset(0, 1).Value = myY
ActiveCell.Offset(0, 2).Value = myZ
Cells(ActiveCell.RoW + 1, 1).Select
Next myY
Next myX
End Sub