Move data from rows into columns

hfler

Board Regular
Joined
Jun 10, 2008
Messages
95
Hello--

I just imported a ton of data from an [COLOR=blue! important][COLOR=blue! important]internet[/COLOR][/COLOR] [COLOR=blue! important][COLOR=blue! important]website[/COLOR][/COLOR] into excel. I want the data to be organized in columns, such as 'company name,' 'contact', 'company description'. However, all of this data is organized into rows instead of columns. How do I convert that data so that, for instance, every third row goes into a column entitled company name, every second row into a column called 'contact', etc.

If anyone has any insight into this, it would be greatly appreciated.

Thanks.
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Excel does a really slick thing....try selecting your data/copy/paste special/transpose. If you need more help let me know.
 
Upvote 0
If you want a macro to do this...

Code:
Sub transpose()
Dim i As Integer
Dim j As Integer
j = 1
For i = 1 To [COLOR=#ff0000]Number of rows you have[/COLOR]
    Cells(j, i).Value = Cells(i, j).Value
    If i = 1 Then
    Else
    Cells(i, j).Value = ""
    End If
Next i
End Sub
 
Upvote 0
Okay, now my excel ineptitude is really coming into play. How do I turn this code into a macro.

Also, to the previous two responses regarding the 'transpose' function, that is not quite what I am looking for... I am trying to select every third row, and then take the data in every third row, and making it into ONE column. So, I am not actually trying to make separate columns for every third row, but just move all of the data from every third row into one column, the data from every second row into another column, etc.

Thanks for your help, and hopefully there is a way to do this!
 
Upvote 0
This is the closest thing I have come up with so far, it adds an extra blank space at the top of the second and third columns.

Rich (BB code):
Sub transpose()
Dim row As Integer
Dim column As Integer
row = 1
rowx = row
column = 1
For column = 2 To 4
    For row = rowx To number of rows you have Step 3
        Cells(row / 3 + 1, column).Value = Cells(row, 1).Value
    Next row
    rowx = rowx + 1
Next column
End Sub

I guess what you could do is at the very end of the code before "End Sub" you can add the following:
Rich (BB code):
Range("A:A").EntireColumn.delete
Range("B1").delete Shift:=xlUp
Range("C1").delete Shift:=xlUp


To put this in a macro, do the following:

1) press Alt+F11 to bring up the macro editor
2) insert > Module
3) copy/paste the code I gave you into the window on the right side
4) Run the macro by pressing alt+f8 and choosing transpose

BACK UP YOUR FILE BEFORE RUNNING ANY MACROS
 
Last edited:
Upvote 0
The following code works so you dont have to edit the macro for the number of rows. It automatically detects how many rows you have in column A. Also, it gets rid of the extra space at the top of columns 2 and 3.

Code:
Sub transpose()
Dim row As Integer
Dim column As Integer
Dim lastrow As Long
row = 1
rowx = row
column = 1
lastrow = Range("A" & Rows.count).End(xlUp).row
For column = 2 To 4
    For row = rowx To lastrow Step 3
        Cells(row / 3 + 1, column).Value = Cells(row, 1).Value
    Next row
    rowx = rowx + 1
Next column
Range("A:A").EntireColumn.delete
Range("B1").delete Shift:=xlUp
Range("C1").delete Shift:=xlUp
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,911
Messages
6,122,195
Members
449,072
Latest member
DW Draft

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top