Organizing Raw Data

crismat09

New Member
Joined
Mar 18, 2009
Messages
12
Hi All,

I need to organize some data coming from a raw spreadsheet into a separated table as displayed below.

Raw DataRearranged Table
AB123
1GreenGreenGreenBlue
1RedRedOrangeGreen
1BlueBlueRedRed
2Green
2Orange
2Red
3Blue
3Green
3Red

<colgroup><col span="2"><col><col span="3"></colgroup><tbody>
</tbody>

RAW DATA: Column A represents countries and column B shows the products sold to each country.

I tried to use VLOOKUP and INDEX/MATCH, but both do not produce the expected results. Also tried using PivotTable, but no satisfactory results as well.

Any assistance is much appreciated.

Cris
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
crismat09,

Here is a macro solution for you to consider.

With your raw data in range A1:B9, the results will be written to range D1:F9.

Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

1. Copy the below code
2. Open your NEW workbook
3. Press the keys ALT + F11 to open the Visual Basic Editor
4. Press the keys ALT + I to activate the Insert menu
5. Press M to insert a Standard Module
6. Where the cursor is flashing, paste the code
7. Press the keys ALT + Q to exit the Editor, and return to Excel
8. To run the macro from Excel press ALT + F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.

Code:
Sub ReorganizeData()
' hiker95, 11/29/2017, ME1033369
' Thank you: MickG , 2 / 2 / 2011, MG02Feb42
Dim rng As Range, r As Range
Dim o As Variant, omax As Integer, n As Long, lc As Long
Set rng = Range(Range("A1"), Range("A" & Rows.Count).End(xlUp))
ReDim Out(1 To rng.Count, 1 To Columns.Count)
With CreateObject("Scripting.Dictionary")
  .CompareMode = vbTextCompare
  For Each r In rng
    If Not .Exists(r.Value) Then
      n = n + 1
      .Add r.Value, Array(n, 2)
      Out(n, 1) = r.Value: Out(n, 2) = r.Offset(, 1)
    Else
      o = .Item(r.Value)
      o(1) = o(1) + 1
      Out(o(0), o(1)) = r.Offset(, 1)
      .Item(r.Value) = o
      omax = Application.Max(o(1), omax)
    End If
  Next
  Range("D1").Resize(omax, .Count) = Application.Transpose(Out)
  Columns.AutoFit
End With
End Sub

Before you use the macro with Excel 2007 or newer, save your workbook, Save As, a macro enabled workbook with the file extension .xlsm, and, answer the "do you want to enable macros" question as "yes" or "OK" (depending on the button label for your version of Excel) the next time you open your workbook.

Then run the ReorganizeData macro.
 
Upvote 0

Forum statistics

Threads
1,215,408
Messages
6,124,727
Members
449,185
Latest member
ekrause77

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