VBA Loop to Replicate List of Hundreds of SKUs for Hundreds of Locations

vlswanson

New Member
Joined
Jul 7, 2006
Messages
16
Office Version
  1. 2021
Platform
  1. Windows
I admittedly use VBA very infrequently, but seems like this should have been a simple exercise!

I have a file with 2 lists, one with a thousand SKUs and one with a hundred locations. I want to end up with 2 columns and 100,000 rows, with the 1,000 sku's with a location number next to them

I've named ranges "SKU_List" and a "Location_List", and would appreciate help in making this happen!

Thank you!

-Vikki
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
paste this code into a module
load the sku's data into sheet : SKU
load the locations into sheet : LOC
then run : combineSku



Code:
Sub combineSku()
Dim colSKU As New Collection
Dim colLOC As New Collection
Dim S As Integer, L As Integer
  
On Error GoTo ErrSku

   'LOAD SKU
Sheets("SKU").Activate
Range("A2").Select
While ActiveCell <> ""
  colSKU.Add ActiveCell.Value
  ActiveCell.Offset(1, 0).Select 'NEXT ROW
Wend


   'LOAD LOCations
Sheets("LOC").Activate
Range("A2").Select
While ActiveCell <> ""
  colLOC.Add ActiveCell.Value
  ActiveCell.Offset(1, 0).Select 'NEXT ROW
Wend


'MERGE
Sheets.Add
ActiveSheet.Name = "merge"
Range("a1").Value = "MERGE"
Range("a2").Select

For S = 1 To colSKU.Count
   For L = 1 To colLoc.Count
      ActiveCell.Offset(0, 0).Value = colSKU(S)
      ActiveCell.Offset(0, 1).Value = colLOC(L)
     
      ActiveCell.Offset(1, 0).Select 'NEXT ROW
   Next
skip2Sku:
Next

MsgBox "done"
Exit Sub

ErrSku:
Resume skip2Sku
End Sub
 
Upvote 0
Where is this list going? Would need to know where to place it. I wouldnt use that last code with 100k rows.
 
Upvote 0
paste this code into a module
load the sku's data into sheet : SKU
load the locations into sheet : LOC
then run : combineSku



Code:
Sub combineSku()
Dim colSKU As New Collection
Dim colLOC As New Collection
Dim S As Integer, L As Integer
 
On Error GoTo ErrSku

   'LOAD SKU
Sheets("SKU").Activate
Range("A2").Select
While ActiveCell <> ""
  colSKU.Add ActiveCell.Value
  ActiveCell.Offset(1, 0).Select 'NEXT ROW
Wend


   'LOAD LOCations
Sheets("LOC").Activate
Range("A2").Select
While ActiveCell <> ""
  colLOC.Add ActiveCell.Value
  ActiveCell.Offset(1, 0).Select 'NEXT ROW
Wend


'MERGE
Sheets.Add
ActiveSheet.Name = "merge"
Range("a1").Value = "MERGE"
Range("a2").Select

For S = 1 To colSKU.Count
   For L = 1 To colLoc.Count
      ActiveCell.Offset(0, 0).Value = colSKU(S)
      ActiveCell.Offset(0, 1).Value = colLOC(L)
    
      ActiveCell.Offset(1, 0).Select 'NEXT ROW
   Next
skip2Sku:
Next

MsgBox "done"
Exit Sub

ErrSku:
Resume skip2Sku
End Sub
While it took a while to run, I now have a list of 126k SKU /Location combinations (there was more than 1000 SKUs and 100 locations ;) ), which is exactly what i was looking for :) Thank you!
 
Upvote 0

Forum statistics

Threads
1,223,898
Messages
6,175,272
Members
452,628
Latest member
dd2

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