Solved

Convert Columns to Rows

Posted on 2012-03-28
11
233 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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
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 500 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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

724 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