Re-organize data from a 2 dimensional grid to a single dimensional grid - see example below

amols.jadhav

New Member
Joined
Aug 22, 2012
Messages
6

Hi Experts,

I am new to this forum, I need help for following query

Re-organize data from a 2 dimensional grid to a single dimensional grid - see example below

source data:

Item Sales MH, GJ, KA
A 1 2 3
B 4 5 6
C 7 8 9


reformat to the following
Item STATE Sales
A MH 1
B MH 4
C MH 7
A GJ 2
B GJ 5
C GJ 8
A KA 3
B KA 6
C KA 9

Thanks,

Amol J
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Anybody know how to do it then please reply




Hi Experts,

I am new to this forum, I need help for following query

Re-organize data from a 2 dimensional grid to a single dimensional grid - see example below

source data:

Item Sales MH, GJ, KA
A 1 2 3
B 4 5 6
C 7 8 9


reformat to the following
Item STATE Sales
A MH 1
B MH 4
C MH 7
A GJ 2
B GJ 5
C GJ 8
A KA 3
B KA 6
C KA 9

Thanks,

Amol J
 
Upvote 0
Give this a try

Code:
Sub abc()
 Dim iCol As Long, LastCol As Long
 Dim irow As Long, LastRow As Long, n As Long
 Dim a() As Variant
 
 LastRow = Cells(Rows.Count, 1).End(xlUp).Row
 LastCol = Cells(1, Columns.Count).End(xlToLeft).Column
 
 ReDim a(1 To (LastRow - 1) * (LastCol - 1), 1 To LastCol - 1)
 
 n = 1
 For iCol = 2 To LastCol
    For irow = 2 To LastRow
        a(n, 1) = Cells(irow, 1)
        a(n, 2) = Cells(1, iCol)
        a(n, 3) = Cells(irow, iCol)
        n = n + 1
    Next
 Next
 Worksheets("Sheet2").Range("a1").Resize(UBound(a), UBound(a, 2)) = a
End Sub
 
Upvote 0
If you want to place the output in different location you can use this
Code:
Sub ReOrg()
Dim r As Long, Lc As Long, Lr As Long
Const c As Integer = 6 ' The first new column
r = 2 'The first new row
Lc = Cells(1, Columns.Count).End(xlToLeft).Column
Lr = Cells(Rows.Count, 1).End(xlUp).Row
For j = 2 To Lc
    For i = 2 To Lr
        Cells(r, c + 1) = Cells(1, j)
        Cells(r, c) = Cells(i, 1)
        Cells(r, c + 2) = Cells(i, j)
        r = r + 1
    Next i
Next j
End Sub
 
Upvote 0
Thanks a lot that's what I was looking for.


Regards,

Amol





If you want to place the output in different location you can use this
Code:
Sub ReOrg()
Dim r As Long, Lc As Long, Lr As Long
Const c As Integer = 6 ' The first new column
r = 2 'The first new row
Lc = Cells(1, Columns.Count).End(xlToLeft).Column
Lr = Cells(Rows.Count, 1).End(xlUp).Row
For j = 2 To Lc
    For i = 2 To Lr
        Cells(r, c + 1) = Cells(1, j)
        Cells(r, c) = Cells(i, 1)
        Cells(r, c + 2) = Cells(i, j)
        r = r + 1
    Next i
Next j
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,936
Messages
6,122,340
Members
449,079
Latest member
rocketslinger

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top