Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default restructure long to wide

I have data that looks like this

Group Eyes Hair Grade
1 Bk Bk 4
1 Bl Bk 6
1 Bk Bk 4
2 Br Br 4
2 Br Br 7
3 Hz Br 6


and so forth where there aren't necessarily the same number of
individuals in each group as in the example above (group 1 n=3, group
2 n=2, group 3 n=1)

I want to restructure it. It's easy to do in SPSS, but I would like to
do it in Excel. It should look like this

Group Feature Result
1 Eyes Bk
1 Eyes Bl
1 Eyes Bk
1 Hair Bk
1 Hair Bk
1 Hair Bk
1 Grade 4
1 Grade 6
1 Grade 4
2 Eyes Br
2 Eyes Br
2 Hair Br
2 Hair Br
2 Grade 4
2 Grade 7
3 Eyes Hz
3 Hair Br
3 Grade 6

Any ideas?

Thanks in advance,
Jeff

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default restructure long to wide

Jeff,

Select a cell in your table, and run the macro below.

You'll need to sort the table and insert your desired headers, but other than that, it works fine.

HTH,
Bernie
MS Excel MVP


Sub MakeTable3()
Dim myCell As Range
Dim newSheet As Worksheet
Dim mySheet As Worksheet
Dim i As Long
Dim j As Integer
Dim k As Long
Dim mySelection As Range

Set mySheet = ActiveSheet
Set mySelection = ActiveCell.CurrentRegion
On Error Resume Next
Application.DisplayAlerts = False
Worksheets("New Database").Delete
Set newSheet = Worksheets.Add
newSheet.Name = "New Database"
mySheet.Activate
i = 1
For j = mySelection(1).Row + 1 To mySelection(mySelection.Cells.Count).Row
For k = mySelection(1).Column + 1 To mySelection(mySelection.Cells.Count).Column
If mySheet.Cells(j, k).Value < "" Then
newSheet.Cells(i, 1).Value = Cells(j, mySelection(1).Column).Value
newSheet.Cells(i, 2).Value = Cells(mySelection(1).Row, k).Value
newSheet.Cells(i, 3).Value = Cells(j, k).Value
i = i + 1
End If
Next k
Next j
Application.DisplayAlerts = True

End Sub

"alphapoint05" wrote in message
oups.com...
I have data that looks like this

Group Eyes Hair Grade
1 Bk Bk 4
1 Bl Bk 6
1 Bk Bk 4
2 Br Br 4
2 Br Br 7
3 Hz Br 6


and so forth where there aren't necessarily the same number of
individuals in each group as in the example above (group 1 n=3, group
2 n=2, group 3 n=1)

I want to restructure it. It's easy to do in SPSS, but I would like to
do it in Excel. It should look like this

Group Feature Result
1 Eyes Bk
1 Eyes Bl
1 Eyes Bk
1 Hair Bk
1 Hair Bk
1 Hair Bk
1 Grade 4
1 Grade 6
1 Grade 4
2 Eyes Br
2 Eyes Br
2 Hair Br
2 Hair Br
2 Grade 4
2 Grade 7
3 Eyes Hz
3 Hair Br
3 Grade 6

Any ideas?

Thanks in advance,
Jeff



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
http://CannotDeleteFile.net - Cannot Delete File? Try Long Path ToolFilename is too long? Computer Complaining Your Filename Is Too Long? TheLong Path Tool Can Help While most people can go about their businessblissfully unaware of the Windo Max Loger Excel Discussion (Misc queries) 0 June 14th 11 04:30 PM
Long Long Long Nested If Function sed Excel Discussion (Misc queries) 4 December 9th 09 06:44 PM
Restructure text order Edward Excel Discussion (Misc queries) 2 April 25th 06 09:43 PM
Make Excel 2000 print long narrow list "snake" on wide paper? steve from mw rms rrd Excel Discussion (Misc queries) 2 March 1st 06 07:25 PM
Please help restructure this code Jako[_81_] Excel Programming 9 September 12th 04 12:48 AM


All times are GMT +1. The time now is 04:30 PM.

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

About Us

"It's about Microsoft Excel"