Combine two lists to create separate records for each item

Devoto18

New Member
Joined
Mar 20, 2009
Messages
6
Hello all,

I did a search for this and didn't find an answer. Maybe I'm not using the correct phrasing for what I want to do.

I have to lists - a list of stores and a list of items. I want to combine them so that each store has every item.

Example:

Stores Items
123 ABC
456 DEF
789 GHI

I want the result to be:
Column A Column B
123 ABC
123 DEF
123 GHI
456 ABC
456 DEF
456 GHI
789 ABC
789 DEF
789 GHI

I have 250 stores and 100 items. Is there any easy way to do this? Thanks.
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Devoto18,

I have to lists - a list of stores and a list of items. I want to combine them so that each store has every item.

I am assuming that the list of Stores and the list of Items have no duplicates.


Before the macro:


Excel Workbook
ABCDE
1StoresItems
2123ABC
3456DEF
4789GHI
51234
62345
73456
8
9
10
11
12
13
14
15
16
17
18
19
Sheet1



After the macro:


Excel Workbook
ABCDE
1StoresItemsStoresItems
2123ABC123ABC
3456DEF123DEF
4789GHI123GHI
51234456ABC
62345456DEF
73456456GHI
8789ABC
9789DEF
10789GHI
111234ABC
121234DEF
131234GHI
142345ABC
152345DEF
162345GHI
173456ABC
183456DEF
193456GHI
Sheet1




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).

Press and hold down the 'ALT' key, and press the 'F11' key.

On the 'Insert' menu, click 'Module'.

Copy the below code, and paste it into the Module (on the right pane).


Code:
Option Explicit
Sub CreateNewList()
Dim SLR As Long, ILR As Long, NLR As Long, i As Long
  Application.ScreenUpdating = False
  SLR = Cells(Rows.Count, 1).End(xlUp).Row
  ILR = Cells(Rows.Count, 2).End(xlUp).Row
  Range("A1:B1").Copy Range("D1")
  For i = 2 To SLR Step 1
    NLR = Cells(Rows.Count, 4).End(xlUp).Row + 1
    Cells(i, 1).Copy Range(Cells(NLR, 4), Cells(NLR + ILR - 2, 4))
    Range(Cells(2, 2), Cells(ILR, 2)).Copy Cells(NLR, 5)
  Next i
  Application.ScreenUpdating = True
End Sub


With your data on the active worksheet as displayed above, run the "CreateNewList" macro.


Have a great day,
Stan
 
Last edited:
Upvote 0
Thanks a lot, stanleydgromjr! That worked perfectly.

I've been trying to work through Walkenbach's Excel 2003 Power Programming and I just can't get VBA to be anything other than greek to me. I don't know how you guys make it look so easy.

Thanks again for taking the time.

D
 
Upvote 0
Devoto18,

I've been trying to work through Walkenbach's Excel 2003 Power Programming and I just can't get VBA to be anything other than greek to me. I don't know how you guys make it look so easy.

We all started from scratch at some time. You just need something to create for yourself that will make your job easier and faster. You then become more valuable. But, because you can turn work around faster than everyone else, you get more work to do. :)


Try some of these:

Excel Tutorials and Tips - VBA - macros - training
http://www.mrexcel.com/articles.shtml

How to Learn to Write Macros
http://articles.excelyogi.com/playin...ba/2008/10/27/

Click here and scroll down to Getting Started with VBA.
http://www.datapigtechnologies.com/ExcelMain.htm

If you are serious about learning VBA try
http://www.add-ins.com/vbhelp.htm


And, when you begin to feel more comfortable writing code, try answering some of the posts here on MrExcel, and
http://www.excelforum.com/index.php
http://www.ozgrid.com/
http://www.vbaexpress.com/portal.php


Have a great day,
Stan
 
Upvote 0

Forum statistics

Threads
1,207,168
Messages
6,076,907
Members
446,239
Latest member
Home Nest

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