PC Review


Reply
Thread Tools Rate Thread

Combine multiple columns into two long columns, Repeating rows in first column

 
 
anasab@gmail.com
Guest
Posts: n/a
 
      31st Jul 2006

I need help combining data in multiple columns into two long columns
with the rows in the first column repeating:

Example

Start

Column1, Column2, column3, Column4, Column5
Joe, 1000, 15000, 300, 20
Mike, 400, 5000, 37, 500
Gary, 90, 3000, 100, 66


End

Column1, Column2
Joe, 1000
Joe, 15000
Joe, 300
Joe, 20
Mike, 400
Mike, 5000
Mike, 37
...................

Thanks

 
Reply With Quote
 
 
 
 
=?Utf-8?B?VG9wcGVycw==?=
Guest
Posts: n/a
 
      31st Jul 2006
Try this - copy code into a general module (VBE) and run the macro:

It will copy data from Sheet1 to Sheet2 starting row 1 with data assumed to
be in columns A & B.

Sub Column2Row()

Dim ws1 As Worksheet, ws2 As Worksheet
Dim lastrow As Long, r As Long, rr As Long, c As Long

Set ws1 = Worksheets("Sheet1")
Set ws2 = Worksheets("Sheet2")

With ws1

lastrow = .Cells(Rows.Count, "A").End(xlUp).Row
rr = 0
' data starting in row 1

For r = 1 To lastrow
ncol = .Cells(r, Columns.Count).End(xlToLeft).Column

For c = 2 To ncol
rr = rr + 1
ws2.Cells(rr, "A") = .Cells(r, "A")
ws2.Cells(rr, "B") = .Cells(r, c)
Next c

Next r

End With

End Sub

HTH

"(E-Mail Removed)" wrote:

>
> I need help combining data in multiple columns into two long columns
> with the rows in the first column repeating:
>
> Example
>
> Start
>
> Column1, Column2, column3, Column4, Column5
> Joe, 1000, 15000, 300, 20
> Mike, 400, 5000, 37, 500
> Gary, 90, 3000, 100, 66
>
>
> End
>
> Column1, Column2
> Joe, 1000
> Joe, 15000
> Joe, 300
> Joe, 20
> Mike, 400
> Mike, 5000
> Mike, 37
> ...................
>
> Thanks
>
>

 
Reply With Quote
 
=?Utf-8?B?ZXhjZWxlbnQ=?=
Guest
Posts: n/a
 
      31st Jul 2006
another way
names:
=OFFSET(A$1,ROUNDUP(CELL("row",A1)/4,0),0)
numbers:
=OFFSET($A$1,ROUNDUP(CELL("row",A1)/4,0),IF(MOD(CELL("row",A1),4)=0,4,MOD(CELL("row",A1),4)))


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
repeating columns containing rows going beyond the repeated column annoni Microsoft Excel Misc 0 25th Jun 2008 03:01 PM
Combine multiple columns and rows for one record into one row. Bowtie63 Microsoft Excel Misc 2 16th Feb 2008 04:20 AM
Combine multiple columns into two long columns, Repeating rows in first column anasab@gmail.com Microsoft Excel Misc 0 31st Jul 2006 05:07 PM
SQL to combine columns of multiple rows into one row =?Utf-8?B?cmxn?= Microsoft Access Queries 9 13th Jun 2006 06:51 PM
Combine the data in 2 columns of 20 rows into one column of 40 row =?Utf-8?B?VG9t?= Microsoft Excel Misc 6 3rd May 2006 09:27 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:28 PM.