Quote:
Originally posted by rami.haddad
Does anybody know how to transpose data in Excel?
I want my columns to become rows
I have tried using the TRANSPOSE Function to no avail
|
Hello,
suppose you have data in the range A1:C10. Three columns and 10 rows. The code below will transpose the cells into three rows and ten columns.
Private Sub Disperse()
' Variable Declarations
Dim I As Double
Dim J As Double
Dim doubleArray(9, 2) As Double
' Use two nested For/Next Loops to access both indeces of the array.
For I = 1 To 3
For J = 1 To 10
doubleArray(J - 1, I - 1) = Cells(J, Chr(I + 64)).value
Next J
Next I
' Clear the contents of the range A1: C10.
Range("a1:c10").ClearContents
' Now to swap over rows for columns exchange the indexes J & I.
For I = 1 To 3
For J = 1 To 10
Cells(I, Chr(J + 64)).value = doubleArray(J - 1, I - 1)
Next J
Next I
End Sub