+ Reply to Thread
Results 1 to 2 of 2

transforming a long dataset into a wide format

Hybrid View

  1. #1
    Registered User
    Join Date
    07-30-2013
    Location
    london
    MS-Off Ver
    Excel 2007
    Posts
    1

    transforming a long dataset into a wide format

    hi guys,


    my problem is similar to the one outline here except for the fact that my only variable is GDP
    basically, my dataset looks like:

    region year log_gdp
    region1 2000 4.23
    region1 2001 4.29
    region1 2002 4.27
    region2 2000 4.19
    region2 2001 4.22
    region2 2002 4.24
    ....

    and i would like to make it like this:

    region/year 2000 2001 2002
    region1 4.23 4.29 4.27
    region2 4.19 4.22 4.24

    unfortunately my programming skills are not so advanced and didn't manage to modify the code available in the other thread.

    i would greatly appreciate any help with this problem, as copying and pasting the data is very time consuming.


    thanks,
    dan

  2. #2
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: transforming a long dataset into a wide format

    Sub macro_1()
    Dim ws1, ws2, count1, count2
    Set ws1 = ActiveSheet
    Set ws2 = Sheets.Add
    With ws2
        .Range("A1") = "Region/Year"
        .Range("B1") = 2000
        .Range("C1") = 2001
        .Range("D1") = 2002
    End With
    count1 = 2
    count2 = 2
    Do Until ws1.Range("A" & count1) = ""
        ws2.Range("A" & count2) = ws1.Range("A" & count1)
        ws2.Range("B" & count2) = ws1.Range("C" & count1)
        ws2.Range("C" & count2) = ws1.Range("C" & count1 + 1)
        ws2.Range("D" & count2) = ws1.Range("C" & count1 + 2)
        count1 = count1 + 3
        count2 = count2 + 1
    Loop
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. long to wide transformation of panel data with many variables
    By mradzik79 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-05-2012, 02:44 PM
  2. Long to Wide in excel?
    By zuwanda in forum Excel General
    Replies: 2
    Last Post: 03-06-2012, 09:54 PM
  3. "transpose" long to wide, creating new variables
    By jmgorzo in forum Excel General
    Replies: 4
    Last Post: 07-07-2011, 08:54 PM
  4. transforming raw data to new time format
    By gamuzadt in forum Excel - New Users/Basics
    Replies: 2
    Last Post: 11-16-2009, 11:22 AM
  5. [SOLVED] restructure long to wide
    By alphapoint05 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-09-2005, 09:05 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1