Merging records / creating new columns based on duplicates

duklaprague

New Member
Joined
Jul 19, 2007
Messages
2
Not sure how well I've described that in the title, but I'll do my best to explain what I'm looking to do!

I basically have a table based on a query based on two linked tables in Access.

So 1 table for 'Features' :

FeatureID
Feature
Description
etc

and 1 table for 'Categories' :

FeatureID
Category


In a one-to-many relationship.

So the resulting query table looks like :

FeatureID, Feature, Description, Category


1, Feature1, Description1, Category1
1, Feature1, Description1, Category2
1, Feature1, Description1, Category3
2, Feature2, Description2, Category1
2, Feature2, Description2, Category2
etc

However, we now have a requirement to output this as a flat Excel file, so what we need to do is convert the above to the format :

FeatureID, Feature, Description, Category1, Category2, Category3

1, Feature1, Description1, Category1, Category2, Category3
2, Feature2, Description2, Category1, Category2
etc

Hope that makes sense - couldn't figure out how to do it in Access, but wondered if it was more easily possible in Excel itself?

Cheers.
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Hi
Paste the following codes in the macro window ( alt f8)

Code:
x = Cells(Rows.Count, 1).End(xlUp).Row
For a = 1 To x
Cells(a, 5) = Cells(a, 1) & Cells(a, 2) & Cells(a, 3)
Next a
b = "E1:E" & x
  Range(b).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Range( _
        "F1"), Unique:=True
    y = Cells(Rows.Count, 6).End(xlUp).Row
g= "F1:F" & y
    For c = 1 To x
    d = Application.WorksheetFunction.Match(Cells(c, 5), Range(g), 0)
    e = Cells(2, Columns.Count).End(xlUp).Column
    Cells(d, e + 1) = Cells(c, 4)
    Next c
Run the macro. It will join col A,B & C into Col E, finds unique combinations in Col F and slots categories horizontally.
Ravi
 
Upvote 0
Cheers for that. Not quite what I'm after - but v impressed with what Excel can do.

As some sample data I would have three columns :

ID, Feature, Category

1, 1853 Gallery, Art Gallery
1, 1853 Gallery, Industrial Heritage
1, 1853 Gallery, Specialist Shopping
2, Abbotsbury Swannery, Bird Collection
2, Abbotsbury Swannery, Nature Reserve

That I'm looking to output as five columns :

ID, Feature, Category1, Category2, Category 3

1, 1853 Gallery, Art Gallery, Industrial Heritage, Specialist Shopping
2, Abbotsbury Swannery, Bird Collection, Nature Reserve

What that code does is combine colums A, B and C in columns E and F, ie :

ID, Feature, Category, blank, ABC combined, ABC combined

1, 1853 Gallery, Art Gallery, ,11853 GalleryArt Gallery,11853 GalleryArt Gallery
1, 1853 Gallery, Industrial Heritage, ,11853 GalleryIndustrial Heritage,11853 GalleryIndustrial Heritage
1, 1853 Gallery, Specialist Shopping, ,11853 GallerySpecialist Shopping,11853 GallerySpecialist Shopping
2, Abbotsbury Swannery, Bird Collection, ,2Abbotsbury SwanneryBird Collection,2Abbotsbury SwanneryBird Collection
2, Abbotsbury Swannery, Nature Reserve, ,2Abbotsbury SwanneryNature Reserve,2Abbotsbury SwanneryNature Reserve
 
Upvote 0

Forum statistics

Threads
1,213,484
Messages
6,113,920
Members
448,533
Latest member
thietbibeboiwasaco

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