Generate a list of products and locations in a new sheet based on the value from a cell

Ianmaggy

New Member
Joined
Oct 15, 2015
Messages
5
Hi,

Trying to build an inventory count sheet and I would like to automate the process of adding lines to a sheet when we have 1 product in more than 1 location. Pay attention the the "Bin" column.

Here is what my source data looks like:

Row#WarehouseSKUDescriptionQTYCostBinAX_SKUBinAXMulti bin
904000647H LT225/75R16 115R BR BLIZZAK16165.72BB6-10000647BRIDNULLTRUE
1504000655H LT275/70R18 125R BR BLIZZAK24187.64DA9,DC9000655BRIDNULLTRUE
24704016406H 255/70R17 112S BR BLIZZAK 28151.88EM6,EG2-6016406BRIDNULLTRUE

<tbody>
</tbody>


Here is how I would like the output to look like.

SKUBin LagacyBin AXQty
000647BB6BB6
000647BB7BB7
000647BB8BB8
000647BB9BB9
000647BB10BB10
000655DA9DA9
000655DC9DC9
016406EM6EM6
016406EG2EG2
016406EG3EG3
016406EG4EG4
016406EG5EG5
016406EG6EG6

<tbody>
</tbody>

Thanks to anyone who can help me!

Ian
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Based on your current data, try this for results on sheet2
Code:
[COLOR="Navy"]Sub[/COLOR] MG06Oct36
[COLOR="Navy"]Dim[/COLOR] Rng [COLOR="Navy"]As[/COLOR] Range, Dn [COLOR="Navy"]As[/COLOR] Range, n, Sp [COLOR="Navy"]As[/COLOR] Variant, Sp1 [COLOR="Navy"]As[/COLOR] Variant, nn [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] c [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long[/COLOR]
[COLOR="Navy"]Set[/COLOR] Rng = Range(Range("G2"), Range("G" & Rows.Count).End(xlUp))
c = 1
ReDim Ray(1 To 4, 1 To 1)
Ray(1, c) = "SKU": Ray(2, c) = "Bin Lagacy": Ray(3, c) = "Bin AX": Ray(4, c) = "Qty"
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Dn [COLOR="Navy"]In[/COLOR] Rng
    Sp = Split(Dn.Value, ",")
        [COLOR="Navy"]For[/COLOR] n = 0 To UBound(Sp)
            Sp1 = Split(Sp(n), "-")
                [COLOR="Navy"]If[/COLOR] InStr(Sp(n), "-") [COLOR="Navy"]Then[/COLOR]
                    [COLOR="Navy"]For[/COLOR] nn = Mid(Sp1(0), 3, Len(Sp1(0)) - 2) To Sp1(1)
                        c = c + 1
                        ReDim Preserve Ray(1 To 4, 1 To c)
                        Ray(1, c) = Dn.Offset(, -4).Value
                        Ray(2, c) = Left(Sp1(0), 2) & nn
                        Ray(3, c) = Left(Sp1(0), 2) & nn
                    [COLOR="Navy"]Next[/COLOR] nn
                [COLOR="Navy"]Else[/COLOR]
                     c = c + 1
                     ReDim Preserve Ray(1 To 4, 1 To c)
                     Ray(1, c) = Dn.Offset(, -4).Value
                     Ray(2, c) = Sp(n)
                     Ray(3, c) = Sp(n)
                [COLOR="Navy"]End[/COLOR] If
        [COLOR="Navy"]Next[/COLOR] n
[COLOR="Navy"]Next[/COLOR] Dn
[COLOR="Navy"]With[/COLOR] Sheets("Sheet2").Range("A1").Resize(c, 4)
    .Value = Application.Transpose(Ray)
    .Borders.Weight = 2
    .Columns.AutoFit
    .HorizontalAlignment = xlCenter
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]With[/COLOR]
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0
Pretty similar to Mick's really, but a few variations.
Test with a copy of your workbook.

Code:
Sub Rearrange()
  Dim a As Variant, b As Variant, bits As Variant
  Dim i As Long, j As Long, k As Long, r As Long
  Dim Pref As String
  
  a = Application.Index(Cells, Evaluate("row(2:" & Range("G" & Rows.Count).End(xlUp).Row & ")"), Array(3, 7))
  ReDim b(1 To Rows.Count - 1, 1 To 3)
  For i = 1 To UBound(a)
    bits = Split(a(i, 2), ",")
    For j = 0 To UBound(bits)
      Pref = Left(bits(j), 2)
      For k = Split(Mid(bits(j), 3) & "-" & Mid(bits(j), 3), "-")(0) To Split(Mid(bits(j), 3) & "-" & Mid(bits(j), 3), "-")(1)
        r = r + 1
        b(r, 1) = a(i, 1): b(r, 2) = Pref & k: b(r, 3) = b(r, 2)
      Next k
    Next j
  Next i
  With Sheets.Add(After:=ActiveSheet).Range("A2:C2").Resize(r)
    .Columns(1).NumberFormat = "@"
    .Value = b
    .Rows(0).Resize(, 4).Value = Array("SKU", "Bin Lagacy", "Bin AX", "Qty")
  End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,175
Messages
6,129,299
Members
449,499
Latest member
HockeyBoi

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