Manipulate how Excel data is displayed

Manipulate how data is displayedQuestion:
In the attached Excel file, Sheet1 shows how my data is currently laid out.  I would like to change the layout to how it is shown in Sheet2.  In Sheet2 the sequence of the rows does not matter.  

If a solution can be given in MS Access that would be acceptable too.

Note that the data in my "real" file has a lot more rows and columns of data than the sample data in the attached file. Thanks.  EE01.xlsx
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Install the attached add-in, Table2DB
Select Sheet1, cell C2 (first rate cell) and run the add-in

Glenn RayExcel VBA DeveloperCommented:
The following code will transform the data given the following conditions:
1) The macro is run when the original data set is visible (i.e., Sheet1)
2) State columns begin in column 3 and continue onward
3) There are no blank rows

The code will create a new sheet named "NEW" and place the transformed data there.


Sub Transform_Array()
    Dim rng, rngCat As Range
    Dim r, c, i As Integer
    Dim intCurrRow As Integer
    Dim strSource, strST As String
    strSource = ActiveSheet.Name
    Set rng = ActiveSheet.Range("A1").CurrentRegion
    i = rng.Columns.Count
    r = rng.Rows.Count - 1
    Set rngCat = Range("A2:B" & r + 1)
    ActiveWorkbook.Sheets.Add After:=Worksheets(Worksheets.Count)
    ActiveSheet.Name = "NEW"
    Range("A1").Value = "PrdNam"
    Range("B1").Value = "Tiers"
    Range("C1").Value = "STATE"
    Range("D1").Value = "Rate"
    intCurrRow = 2
    For c = 3 To i
        strST = Cells(1, c).Value
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone
        Range(Cells(intCurrRow, 3), Cells(intCurrRow + r - 1, 3)).Value = strST
        Range(Cells(2, c), Cells(r + 1, c)).Copy
        Cells(intCurrRow, 4).Activate
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone
        intCurrRow = intCurrRow + r
        Cells(intCurrRow, 1).Select
    Next c
    MsgBox "Done."
End Sub

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
RishiSingh05Author Commented:
Thanks, Thomas and Glen.  Pls give me some time to try it.
RishiSingh05Author Commented:
I will be posting a follow-up question to Glen's solution ,,,
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Applications

From novice to tech pro — start learning today.