[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Convert Columns to Rows

Posted on 2012-03-28
11
Medium Priority
?
238 Views
Last Modified: 2012-08-13
Hello:

I am trying to convert data that looks like this:

Oct-2010      Oct-2010      Nov-2010      Nov-2010      Dec-2010      Dec-2010      Jan-2011      Jan-2011
Score      N      Score      N      Score      N      Score      N
 67.3      11743       45.2      9834       71.4      10253       87.1      14374

To look like this:

MthYr            Score           N
Oct-2010        67.3            11743
Nov-2010       45.2              9834
Dec-2010       71.4            10253
Test.xlsx
0
Comment
Question by:RecipeDan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
11 Comments
 
LVL 12

Expert Comment

by:kgerb
ID: 37778370
1.  Copy data in chunks (for example, all the dates)
2.  paste special, select transpose check box, click ok
3.  Ctrl+select all Scores, copy, paste special, transpose, ok
4.  Ctrl+select all N-values, copy, paste special, transpose, ok

Will that work for you?

Kyle
0
 
LVL 26

Expert Comment

by:redmondb
ID: 37778378
Hi, RecipeDan.

As it stands, it's very straightforward. However, I'm assuming that reality is more complicated - lots more columns and/or rows, perhaps? So, how many of each?

Thanks,
Brian.
0
 
LVL 1

Author Comment

by:RecipeDan
ID: 37778412
@Brian: Yes its a little more complicated. I have 24 columns (12 months + 12 N Values) and the number of rows will very based on content.

@Kyle: I am looking for a macro that the users can run. I am working with users who have a very basic knowledge of Excel. The similiar the better.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 26

Expert Comment

by:redmondb
ID: 37778804
RecipeDan,

OK, let's start with the attached. The macro is...
Option Explicit

Sub Reformat_Data()
Dim xInput As Worksheet
Dim xOutput As Worksheet
Dim xLast_Row As Long
Dim xOut_Row As Long
Dim i As Long, j As Long

Set xInput = Sheets("Input")

xLast_Row = xInput.Range("A1").SpecialCells(xlLastCell).Row
If xLast_Row < 3 Then
    MsgBox ("No Data found. Run cancelled.")
    Exit Sub
End If

Application.ScreenUpdating = False
    Set xOutput = Sheets.Add
    
    xOutput.Range("A1:D1") = Array("Row", "MthYr", "Score", "N")
    xOut_Row = 1
    
    With xInput
        For i = 3 To xLast_Row
            For j = 2 To 24 Step 2
                xOut_Row = xOut_Row + 1
                xOutput.Cells(xOut_Row, 1) = .Cells(i, 1)
                xOutput.Cells(xOut_Row, 2) = .Cells(1, j)
                xOutput.Cells(xOut_Row, 3) = .Cells(i, j)
                xOutput.Cells(xOut_Row, 4) = .Cells(i, j + 1)
            Next
        Next
    
    End With
    
    xOutput.Columns("B:B").NumberFormat = "mmm-yyyy"
    
Application.ScreenUpdating = True
    
End Sub

Open in new window

Regards,
Brian.
Test-V3.xlsm
0
 
LVL 1

Author Comment

by:RecipeDan
ID: 37778988
Hi Brian:

It looks good. It is exactly what I am looking for. A couple questions, do I have to put the letters Column A? If I don't have 24 columns, do I change the 24 to how ever many columns I have?

Thanks
Dan
0
 
LVL 26

Accepted Solution

by:
redmondb earned 2000 total points
ID: 37779210
RecipeDan,

do I have to put the letters Column A?
Nope. I've taken them out in the attached.

If I don't have 24 columns, do I change the 24 to how ever many columns I have?
Nearly - one less! (So, V4 uses 23 as there are 24 columns.)

Regards,
Brian.Test-V4.xlsm
0
 
LVL 1

Author Comment

by:RecipeDan
ID: 37779300
Hi Brain:

What if I have 6 months of data (12 columns)? Also I thought of something else past data from prior years has fields before the actual data. I attached an example.

I am trying to think of all scenarios while I have this question open.

Dan
0
 
LVL 1

Author Comment

by:RecipeDan
ID: 37779308
here is the example
TestBook1.xlsx
0
 
LVL 26

Expert Comment

by:redmondb
ID: 37779528
RecipeDan,

What if I have 6 months of data (12 columns)?
Then you use 11. However, this has been overtaken by ...
past data from prior years has fields before the actual data.
It depends what you want to do with the extra fields - simply ignore them or include them as I did with "Row" in V3?
I am trying to think of all scenarios while I have this question open.
I understand why you think that's useful but it tends to waste both our time! Even if you find you've forgotten something then
(a) Post in the closed question. (Not relevant for all Experts, but I keep an eye on "my" closed questions for at least a couple of weeks.)
(b) Ask a new question, including a link to the closed one.

Regards,
Brian.
0
 
LVL 1

Author Comment

by:RecipeDan
ID: 37783284
OK sounds good..Thank you for your help
0
 
LVL 26

Expert Comment

by:redmondb
ID: 37784256
RecipeDan,

Thanks, but what about columns A and B?!

Regards,
Brian.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question