Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

How do I transpose data in columns to rows?

If the data is:

Joe  
some city  
some state  
Bob  
no city  
no state  

and I use Paste Special » Transpose, I get

Joe some city some state Bob no city no state  

What I want is:

Joe some city some state  
Bob no city no state  

I do not know VBA.

share|improve this question
    
That is transposition. –  Ignacio Vazquez-Abrams Mar 8 '12 at 2:21
    
Very similar to this question: superuser.com/questions/113242/excel-transpose-and-organize –  Arkive Mar 8 '12 at 3:30
    
@Arkive it is nearly a dupe but since the data is positioned differently, I'm not sure about closing it. –  Raystafarian Mar 8 '12 at 11:42
add comment

3 Answers 3

We're gonna learn you some VBA this morning and you're going to feel good about that! Put on your rocket boots and get ready to sail!

This macro will do it for you if it's all in column A

Hit Alt + F11 to bring up VBA editor. Right click insert - module. Paste the code below in the module and to go debug - compile project and hit F5 to run it. Easy breezy.

Sub transposedelete()

Dim rownum As Long
Dim colnum As Long
Dim data, result
colnum = 1

Application.ScreenUpdating = False

'check if the data on the sheet start where the code expects it
If Range("a1") = "" Then Exit Sub


    ' define data range
    With Range("a1", Cells(Rows.Count, "a").End(xlUp)).Resize(, 2)
    data = .Value
    numrows = UBound(data)

    'loop it
    For rownum = 2 To numrows

    Range((Cells(rownum, colnum)), (Cells(rownum + 1, colnum))).Copy
    ' transpose
    Cells(rownum - 1, colnum + 1).Select
    Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
        False, Transpose:=True

    'delete rows (this could be cleaner)
    Rows(rownum).Select
    Application.CutCopyMode = False
    Selection.Delete Shift:=xlUp
    Rows(rownum).Select
    Application.CutCopyMode = False
    Selection.Delete Shift:=xlUp


    Next

    End With

    Application.ScreenUpdating = True

End Sub

Easy as 1, 2, 3:

1.
enter image description here
2.
enter image description here
3.
enter image description here

See now that wasn't difficult or intimidating, was it? And now you have a trick up your sleeve! Learning is great fun!

share|improve this answer
add comment

To get the result you're after, you need to start off with your data in two columns instead of 1.

Joe         Bob
some city   no city
some state  no state
share|improve this answer
add comment

update: Excel 2007 and later actually does have a one-column-to-multiple-rows feature. Read about it here. For the reason the transpose feature isn't doing what you want, see below:

In order for transposition to work the way you want, your original data would need to be arranged like this:

Joe        Bob
city1      city2
state1     state2

Transposition changes rows to columns and vice versa. The way your information is formatted in your example, it's all one long column and excel changes it to one long row. It has no way of knowing that you want it to treat your column with six items as two blocks of three items each.

share|improve this answer
1  
The article you link to is how to split one column to multiple columns, not rows. –  mischab1 Mar 9 '12 at 19:53
    
When you put multiple columns side-by-side, you've created rows. Depending on how the data in the single column are laid out, you might have to transpose after breaking into multiple columns. –  octern Mar 9 '12 at 21:48
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.