Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1
Default Multiple rows from a single row

Hi,
I've got a worksheet with the following data (for example).
ID, Field 1, Field 2
1, hello, world
2, here, again

I'm looking to put it in the format

ID, FieldName, FieldValue
1, Field1, hello
1, Field2, world
2, Field1, here
2, Field2, again

As you can see I'm mapping the column headers into row values (column
2) and thier related value into row values (column3). For each
combination I've got to repeat the row ID.

I think this can only be done via a macro? Is this right..and can you
help (in reality I've got about 25 different fields and the number of
rows is variable)??

Thanks in advance
Nick

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Multiple rows from a single row

One way is to use a macro:

Option Explicit
Sub testme01()

Dim CurWks As Worksheet
Dim NewWks As Worksheet
Dim oRow As Long
Dim iCol As Long
Dim FirstRow As Long
Dim LastRow As Long
Dim iRow As Long

Set CurWks = Worksheets("sheet1")
Set NewWks = Worksheets.Add

NewWks.Range("a1").Resize(1, 3).Value _
= Array("ID", "FieldName", "FieldValue")

oRow = 2
With CurWks
FirstRow = 2 'headers in row 1
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row

For iRow = FirstRow To LastRow
For iCol = 2 To .Cells(iRow, .Columns.Count).End(xlToLeft).Column
NewWks.Cells(oRow, "A").Value = .Cells(iRow, "A").Value
NewWks.Cells(oRow, "B").Value = .Cells(1, iCol).Value
NewWks.Cells(oRow, "C").Value = .Cells(iRow, iCol).Value
oRow = oRow + 1
Next iCol
Next iRow
End With

End Sub

If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

wrote:

Hi,
I've got a worksheet with the following data (for example).
ID, Field 1, Field 2
1, hello, world
2, here, again

I'm looking to put it in the format

ID, FieldName, FieldValue
1, Field1, hello
1, Field2, world
2, Field1, here
2, Field2, again

As you can see I'm mapping the column headers into row values (column
2) and thier related value into row values (column3). For each
combination I've got to repeat the row ID.

I think this can only be done via a macro? Is this right..and can you
help (in reality I've got about 25 different fields and the number of
rows is variable)??

Thanks in advance
Nick


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 751
Default Multiple rows from a single row

Hi, just for the fun of it, one way with formulas,

Assume you start your output in F6, with headers in F5:H5, input starts
at A2, with headers in A1:C1 (i.e. 3 columns).

In F6:
=OFFSET($A$1,1+INT(SUM(ROW()-ROW($F$6))/3),0)

In G6:
=OFFSET($A$1,0,1+MOD(SUM(ROW()-ROW($F$6)),3))

In H6:
=OFFSET($A$1,1+INT(SUM(ROW()-ROW($F$6))/3),1+MOD(SUM(ROW()-ROW($F$6)),3))

Copy down.

HTH
Kostis Vezerides


wrote:
Hi,
I've got a worksheet with the following data (for example).
ID, Field 1, Field 2
1, hello, world
2, here, again

I'm looking to put it in the format

ID, FieldName, FieldValue
1, Field1, hello
1, Field2, world
2, Field1, here
2, Field2, again

As you can see I'm mapping the column headers into row values (column
2) and thier related value into row values (column3). For each
combination I've got to repeat the row ID.

I think this can only be done via a macro? Is this right..and can you
help (in reality I've got about 25 different fields and the number of
rows is variable)??

Thanks in advance
Nick


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
can i wrap rows to form multiple rows per row to fit on 1 sheet? Dave Excel Discussion (Misc queries) 2 October 9th 12 04:53 PM
Consolidate multiple spreadsheets into a single workbook Andy T Excel Discussion (Misc queries) 0 April 24th 06 01:13 PM
combining multiple rows of data into one single row of data myersjl Excel Worksheet Functions 0 March 30th 06 10:39 PM
generate multiple rows based on cell value Theresa Excel Worksheet Functions 0 May 25th 05 11:18 PM
how do I easily convert a single column of text (multiple rows si. philmah Excel Discussion (Misc queries) 2 December 16th 04 12:24 AM


All times are GMT +1. The time now is 01:17 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"