+ Reply to Thread
Results 1 to 5 of 5
  1. #1
    Forum Contributor
    Join Date
    07-25-2008
    Location
    texas
    Posts
    170

    Reverse pivot table

    I have a table that looks like the results of a pivot table.
    It has employees down the rows and the classes they took as columns. There is a date of the class to indicate the employee took that particular class. How can I get this into a "database" structure of:
    employee, class code, class date.?

    Is there a "unpivot"?
    Last edited by jartzh; 03-12-2010 at 12:27 PM.

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    2003 & 2007 & 2010
    Posts
    10,944

    Re: Reverse pivot table

    Is your table a pivot table, or is it just a table of data?

    It will help if you can post example workbook.
    Cheers
    Andy
    www.andypope.info

  3. #3
    Forum Contributor
    Join Date
    07-25-2008
    Location
    texas
    Posts
    170

    Re: Reverse pivot table

    Here is a sample of the problem: its not the result of a pivot table. It just looks like it.
    Attached Files Attached Files

  4. #4
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    2003 & 2007 & 2010
    Posts
    10,944

    Re: Reverse pivot table

    This will produce a 'database' from the table.

    Code:
    Sub MakeData()
        Dim rngData As Range
        Dim rngOutput As Range
        Dim lngRow As Long
        Dim lngCol As Long
        
        Set rngData = Range("B2:J18")
        Set rngOutput = Range("M1")
        
        rngOutput.Resize(1, 3) = Array("Classes", "Employee", "Date")
        Set rngOutput = rngOutput.Offset(1)
        
        For lngRow = 2 To rngData.Rows.Count
            For lngCol = 2 To rngData.Columns.Count
                If Len(rngData.Cells(lngRow, lngCol).Value) > 0 Then
                    rngOutput.Offset(0, 0) = rngData.Cells(1, lngCol) ' class
                    rngOutput.Offset(0, 1) = rngData.Cells(lngRow, 1) ' Employee
                    rngOutput.Offset(0, 2) = rngData.Cells(lngRow, lngCol) ' Date
                    Set rngOutput = rngOutput.Offset(1)
                End If
            Next
        Next
        
    End Sub
    Cheers
    Andy
    www.andypope.info

  5. #5
    Forum Contributor
    Join Date
    07-25-2008
    Location
    texas
    Posts
    170

    Re: Reverse pivot table

    Andy,
    You are the man.

    This is perfect.

    Thanks

Thread Information

Users Browsing this Thread

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

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.2.0