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.
 

Some videos you may like

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.

Ruthanne

Board Regular
Joined
Mar 2, 2004
Messages
123
Excel does a really slick thing....try selecting your data/copy/paste special/transpose. If you need more help let me know.
 

MrKowz

Well-known Member
Joined
Jun 30, 2008
Messages
6,653
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
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
 

hfler

Board Regular
Joined
Jun 10, 2008
Messages
95

ADVERTISEMENT

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!
 

MrKowz

Well-known Member
Joined
Jun 30, 2008
Messages
6,653
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
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:

MrKowz

Well-known Member
Joined
Jun 30, 2008
Messages
6,653
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
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
 

Watch MrExcel Video

Forum statistics

Threads
1,122,569
Messages
5,596,915
Members
414,110
Latest member
docops

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
Top