简体   繁体   中英

How do I transpose a column to a matrix in a new sheet in Excel?

I am not much of an Excel user, but one client is insisting I use it.

I have data in 1728 cells in a column. I want to convert it to a 64x27 matrix in a new sheet. I found the OFFSET function and tried

=OFFSET(ThreePeople!A2:A1729,64,27)

but this gave an error (!VALUE) and asking for "help on this error" was not helpful.

What am I doing wrong?

EDIT: Apparently OFFSET is the wrong function. Sorry.

I want a matrix with 64 rows and 27 columns. Cell A2 in the column would go to cell A1 in the new sheet, then:

A3 to A2 .....A28 to A27, A65 to A64, A66 to B2 ..... and so on.

I did this in SAS with this code:

 horiz = mod(location-1, 27);
 vert = int(location/27) + 1;

where "location" would be the row number of the original data and horiz and vert would be the places where I want the new data.

Put either formula below in cell A1 :

To get 27x64 use this formula:

=OFFSET(ThreePeople!$A2,COLUMNS(ThreePeople!$A2:A2)-1+(ROWS($1:1)-1)*64,0)

Drag it to cell AA1 and then drag that range 27 rows down. This fill from left to right / top to bottum.

To get 64x27 use this formula:

=INDEX(ThreePeople!$A$2:$A$1729,ROW(A1)+(64*(COLUMNS($A$1:A$1)-1)))

Drag it down to cell A64 then drag the range to column 27 (AA). This fills from top to bottom / left to right.

you could create a macro that would do it for you

Sub SplitColumn()

Dim rng As Range
Dim InputRng As Range
Dim OutRng As Range
Dim xRow As Integer
Dim xCol As Integer
Dim xArr As Variant
Set InputRng = Application.Selection
Set InputRng = Application.InputBox("Range :", xTitleId, InputRng.Address, Type:=8)
xRow = Application.InputBox("Rows :", xTitleId)
Set OutRng = Application.InputBox("Out put to (single cell):", xTitleId, Type:=8)
Set InputRng = InputRng.Columns(1)
xCol = InputRng.Cells.Count / xRow
ReDim xArr(1 To xRow, 1 To xCol + 1)
For i = 0 To InputRng.Cells.Count - 1
    xValue = InputRng.Cells(i + 1)
    iRow = i Mod xRow
    iCol = VBA.Int(i / xRow)
    xArr(iRow + 1, iCol + 1) = xValue
Next
OutRng.Resize(UBound(xArr, 1), UBound(xArr, 2)).Value = xArr
End Sub

After this you run the macro, select the cells you want to transpose, type in how many rows and select the output cell

我会使用INDEX()

=INDEX(ThreePeople!$A:$A,ROWS($1:1)+1+(COLUMNS($A:A)-1)*64)

=INDEX(newsheet!$A:$A,ROW(A1)*64-64+COLUMN(A1))
fill formula 64 right and 27 down (a1=1, a2=2 etc)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM