If you dispose of the newer dynamic functions of MS 365 it suffices to enter
the following formula in any target range to get a spilling result:
=LET(data,A1:P10,r,SEQUENCE(4,1,1,3),c,SEQUENCE(1,4,1,5),INDEX(data,r,c))
If you prefer a VBA approach you might use the following procedure;
it
- gets the needed data into a 2-dim data field array (see
1.
)
- calculates the needed row & column indices via
Sequence()
(see 2.a)
) and
- passes them
to the
Index()
function executing the transformation into a 4x4 matrix (see 2.b)
):
Sub transform(rng As Range, _
Optional ByVal rowOffset As Long = 3, _
Optional ByVal colOffset As Long = 5)
'Note: assumes 4x4 matrix with start in first row/column element
'1. get data (1-based 2-dim datafield array)
Dim data: data = rng.Value2
'2. transform data
With Application
'a) define row/column indices to be maintained
Dim r: r = .Sequence(4, 1, 1, rowOffset) ' vert 1 ..4 ..7 ..10
Dim c: c = .Sequence(1, 4, 1, colOffset) ' flat Array(1,6,11,16)
'b) transform data
data = .Index(data, r, c) ' reduce to 4x4 matrix
End With
'3. write data to any target ' change to your needs
Sheet2.Range("A1").resize(UBound(data), UBound(data, 2)) = data
End Sub
Example call
Sub ExampleCall()
Dim rng As Range
Set rng = Sheet1.Range("A1:P10")
transform rng
End Sub
For more backwards compatibility you could replace the sequence function by your own udf