Link to home
Start Free TrialLog in
Avatar of gregfthompson
gregfthompsonFlag for Australia

asked on

Excel - Copy contents of some cells in Sheet2 into rows with same suburb & postcode in Sheet1

The attached file contains 2 worksheets.
Sheet 1 contains 3 columns - Local Zone numbers, Postcode numbers, Suburb names. For each Postcode/Suburb combination there are many Local Zone numbers. There are also different suburb names against the same postcode number.

Sheet 2 contains 4 columns - Postcode, Suburb, Masthead name, Colour code. This list also has different suburb names against the same postcode.

The requirement is to copy the masthead name and colour code from Sheet2 into Sheet1, into the same row as the Postcode/Suburb combination, and repeat it as many times as the Postcode/Suburb combination appears.
And where there is another Masthead/Colour code for the same Postcode/Suburb, include this in the next columns.

Part of the first two masthead/colour codes have been copied manually to indicate the required result.
Masthead-to-Local-Zone-example.xlsx
Avatar of als315
als315
Flag of Russian Federation image

Can it be done in vba?
It can be done by a few filtering, copying, and remove duplicates.

Something is wrong with the data.
Only 2 Masthead types, Central Courier, and Wentworth Courier, where result has 9.
There are no Masthead values below row 191 in the data.

Most of the Postcode-Suburbs-Masthead on the result sheet are not on the input sheet.
Some Suburbs are not there at all.
Examples row 5, Town Hall, row 14, East Sydney

Please upload a new sheet with all data.
SOLUTION
Avatar of als315
als315
Flag of Russian Federation image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Sorry, misunderstood the requirement.
Skip my comment.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
It is very good to have many experts.
My code - 374 s
Egil's - 55 s
Subodh is a champion with 23 s (my computer seems not to be so fast)

I hope it is one time task, so did not spend many time to optimization
Avatar of gregfthompson

ASKER

Thank you all for you help on this.
I tried them all.
als315 - your version appeared to omit the first and last in any group
Subodh - your version also appeared to omit the first and last in any group.
Ejgil - your version took the longest but it appears to copy against all matching postcodes/suburbs.
Thanks very much for your help.