PDA

View Full Version : Transposing arrays to the worksheet



Rasm
11-01-2011, 04:39 AM
I am using the code below to move data from a two dimensional array to the worksheet – I would however like to only transpose certain elements within the array – so let’s say the array is 7 by 12 elements - is there a way to only transpose the elements 3,2 to 3,9 (my arrays are option base zero).
If this cannot be done – what is the best way to create a new array that only contain the elements 3,2 to 3,9 – that way I can still use the .transpose function. My arrays are quite large and I don’t want to use a loop – as it is too slow.




Astr = Split(Cells(1, ColFirst).Address, "$")(1) & LastRow + 1 & ":" & _
Split(Cells(1, ColFirst + UBound(Pnames) - 1).Address, "$")(1) & _
LastRow + 1 + UBound(WetChem, 2) - 1


ActiveSheet.Range(Astr).Value = Application.WorksheetFunction.Transpose(WetChem)


https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA (https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA)

Admin
11-01-2011, 12:02 PM
Hi Rasm,

You mean something like this


Sub kTest()

Dim Ary1, Ary2

Ary1 = [a1:e10]

'picks data from 2nd,3rd and 4th column of 3rd row from array Ary1
Ary2 = Application.Index(Ary1, 3, [{2,3,4}]) 'Array(2,3,4)

[g1].Resize(, UBound(Ary2, 1)) = Ary2

End Sub