Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / New Users / May 2008

Tip: Looking for answers? Try searching our database.

Re-arranging table using pivot-table?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Orlando Acevedo - 13 May 2008 18:02 GMT
I have a worksheet with data organized somewhat like this:

New York      New York
New York      Albany
Florida            Miami
Florida            Orlando
Florida            Tampa
Florida            Jacksonville
California        Los Angeles
California        San Diego

I need to convert this to a list of states and each city in the columns to
the right of their corresponding state. Something like this:

New York        New York        Albany
Florida              Miami               Orlando        Tampa
Jacksonville
California          Los Angeles      San Diego

Any help is greatly appreciated.

Thank you!
Bernie Deitrick - 13 May 2008 18:51 GMT
Orlando,

Use a macro.  Select a cell in your table, then run the macro below.  I've assumed that you have a
header row.

It will put the desired table onto a sheet named  Cross Tab Data

HTH,
Bernie
MS Excel MVP

Sub DBtoCrossTab()
Dim myCell As Range
Dim myTable As Range
Dim mySht As Worksheet
Dim myRow As Long

Set myTable = ActiveCell.CurrentRegion

On Error Resume Next
Application.DisplayAlerts = False
Worksheets("Cross Tab Data").Delete
Application.DisplayAlerts = True

Set mySht = Worksheets.Add
mySht.Name = "Cross Tab Data"

myTable.Rows(1).EntireRow.Copy mySht.Rows(1)

Set myTable = myTable.Offset(1, 0).Resize _
  (myTable.Rows.Count - 1, myTable.Columns.Count)

For Each myCell In myTable.Columns(1).Cells
If IsError(Application.Match(myCell.Value, _
   mySht.Range("A:A"), False)) Then
  myCell.EntireRow.Copy _
       mySht.Range("A65536").End(xlUp)(2).EntireRow
Else
myRow = Application.Match(myCell.Value, _
   mySht.Range("A:A"), False)
   myCell.Offset(0, 1).Resize(1, myTable.Columns.Count - 1).Copy _
     mySht.Cells(myRow, 256).End(xlToLeft)(1, 2)
End If
Next myCell

End Sub

>I have a worksheet with data organized somewhat like this:
>
[quoted text clipped - 17 lines]
>
> Thank you!
Herbert Seidenberg - 14 May 2008 05:02 GMT
With Pivot Table assist
and Index/Match:
http://www.savefile.com/files/1556310

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.