Macro to convert column data to "raw data"

michaelr81

New Member
Joined
Apr 25, 2014
Messages
7
Hello all,
I would like to convert the data arranged in columns into a raw data format. Something similar to a reverse pivot table. It's possible that I will have around 2000 rows (items) and 1000 columns (locations) in the original format, maybe even more. Also the data may start from a different row or column number, but I can rearrange it as required.

Unfortunately transpose does not work here. Could any one kindly help ? Thank you : )

1682410296328.png
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Hi
What about
VBA Code:
Sub test()
Dim a, d
Dim i&, ii&, c&
a = Sheets("sheet3").UsedRange  ' Change sheets name to yours
With CreateObject("scripting.dictionary")
        For ii = 4 To UBound(a, 2)
            d = Split(a(1, ii)): d = Join(Array(d(0), d(1)))
            For i = 2 To UBound(a)
                     If a(i, ii) <> "" Then .Add a(i, 1) & "|" & a(i, 2) & "|" & a(i, 3) & "|" & d & "|" & a(i, ii), ""
            Next
        Next
a = Application.Transpose(.keys)
End With
With Sheets("Destination").Cells(2, 1).Resize(UBound(a) ) ' Change sheets name to yours
    .CurrentRegion.ClearContents
    .Offset(-1).Resize(1, 5) = Array("item", "color", "Description", "location Name", "Order")
    .Value = a
    .Resize(UBound(a)).Columns(1).TextToColumns .Cells(1, 1), 1, other:=True, otherchar:="|"
    .Offset(-1).Resize(, 5).HorizontalAlignment = xlCenter
    .Columns.AutoFit
   End With
End Sub
 
Last edited:
Upvote 0
Solution
You are very welcome
And thank you for the feedback
Be happy and safe
 
Upvote 0

Forum statistics

Threads
1,214,608
Messages
6,120,500
Members
448,968
Latest member
screechyboy79

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