VBA for Ordering List

jay_hl

New Member
Joined
Jun 28, 2012
Messages
27
Hello

I have a large table containing 5000 products down the left side, and 100 stores across the top. The number in the table, is the quality of products to order for that particular store.

To upload the order to the system I need a flat list of only those items which need ordering. I have given simplified structures of both the input matrix, and output needed. (PCS is always the same and standard).

Hope someone can help produce something which creates the example in columns J to M

Thanks in advance

Jay

1713433572920.png
 
The array in vk at the moment is one continuous list, with no second header row, or blank rows. The ask is to help tweak the VBA to include the blank lines when Column 2 changes, and then the header row when the value in Column A changes.

Thanks again
 
Upvote 0

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Can describe which part is the data & which part is the result?
 
Upvote 0
The data is from another tab, and similar to the original ask where you kindle provided the original code back in April, builds an array. This is now written into vk as a continuous list and seems to work fine across the 6 columns

I need to start to include blank lines into the array where the second column value changes, and then also include 2 blank lines and the header row (row 1) where the first column changes. This is where I hope to have the output in the table I just posted.

I have tried to adapt the code but unfortunatly have failed, and hence reaching out again
 
Upvote 0
The data is from another tab, and similar to the original ask where you kindle provided the original code back in April, builds an array.
Can post the data that produce the result in post #20 via xl2bb?
 
Upvote 0
Sure. I have had to clense the data, so the mapping between SKU's/Barcodes are random numbers, but the quantities and stores should match

OutputOutputOutputOutputOutputOutputOutputOutputOutputOutputOutputOutput
32121711212131024850012
Store 1Store 1Store 1Store 2Store 2Store 2Store 3Store 3Store 3Store 4Store 4Store 4
SKUBarcodeDescriptionStore 2Store 3Store 4Store 1Store 3Store 4Store 1Store 2Store 4Store 1Store 2Store 3
13006659376829Desc 1127
29794474246254Desc 212676
34578862098120Desc 31515
46093075590909Desc 487
55850270193908Desc 56
67445040026902Desc 68810
72266579890238Desc 714
87376956442152Desc 87
95999485927439Desc 9666
108944458302678Desc 108
112367021730597Desc 116
128689534241867Desc 12666
134991814575809Desc 1310141013
146397169214139Desc 141228
151734449358502Desc 1576
162138913350369Desc 161717
175494634880055Desc 171078
187846224389136Desc 1810
198023509111679Desc 1922
202276231770354Desc 207
214015975643396Desc 218
229968914563439Desc 2277
236349435210786Desc 232919
243605446742584Desc 2466
252776773813583Desc 2513
 
Upvote 0
Ok, I'll try to amend the code tomorrow when I have time.
 
Upvote 0
Thanks very much. I also realise I might have messed up the first number in the array, which doesnt seem to be coming across in the code that I have butchered together. "the first 12 doenst come through somehow".
 
Upvote 0
Ok I think I just fixed the first number issue. So one down, but two more items still to go :( (blank lines and the header row).

At last I feel like im trying to crack this, although lots of trial and error!

VBA Code:
Dim i As Long, j As Long, n As Long, k As Long, p As Long, q As Long
Dim va, vb, vc, vd, ve, vf, vg, vk
n = Range("A" & Rows.Count).End(xlUp).Row
va = Range("A5:A" & n)
vb = Range("B5:B" & n)
vc = Range("C5:C" & n)
p = Range("A1:BZ1").Find(What:="Output", LookIn:=xlValues, lookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False).Column
q = Range("A1:BZ1").Find(What:="Output", LookIn:=xlValues, lookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlPrevious, MatchCase:=False, SearchFormat:=False).Column

ve = Range(Cells(3, p), Cells(3, q))
vf = Range(Cells(4, p), Cells(4, q))
vg = Range(Cells(5, p), Cells(n, q))

ReDim vk(1 To 1000000, 1 To 6)
            vk(1, 1) = "Move " & Chr(10) & "From"
            vk(1, 2) = "Move " & Chr(10) & "To"
            vk(1, 3) = "SKU"
            vk(1, 4) = "Barcode"
            vk(1, 5) = "Description"
            vk(1, 6) = "Quantity to Transfer"
            k = 1
  For j = 1 To UBound(vg, 2)
    For i = 2 To UBound(vg, 1)
        If vg(i, j) <> "" Then
            k = k + 1
            vk(k, 1) = ve(1, j)
            vk(k, 2) = vf(1, j)
            vk(k, 3) = va(i, 1)
            vk(k, 4) = vb(i, 1)
            vk(k, 5) = vc(i, 1)
            vk(k, 6) = vg(i, j)
        End If
    Next
Next
 
Upvote 0
Try this:
Data in Sheet1 & result in Sheet2 (change to suit):
VBA Code:
Sub jay_hl_4()
Dim i As Long, j As Long, n As Long, k As Long, p As Long, q As Long, m As Long
Dim va, vb, vc, vd, ve, vf, vg, vk
Sheets("Sheet1").Activate 'adjust sheet's name!
n = Range("A" & Rows.Count).End(xlUp).Row
va = Range("A5:A" & n)
vb = Range("B5:B" & n)
vc = Range("C5:C" & n)
p = Range("A1:BZ1").Find(What:="Output", LookIn:=xlValues, lookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False).Column
q = Range("A1:BZ1").Find(What:="Output", LookIn:=xlValues, lookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlPrevious, MatchCase:=False, SearchFormat:=False).Column

ve = Range(Cells(3, p), Cells(3, q)) 'first store
vf = Range(Cells(4, p), Cells(4, q)) 'second store
vg = Range(Cells(5, p), Cells(n, q))

ReDim vk(1 To 1000000, 1 To 6)
            vk(1, 1) = "Move " & Chr(10) & "From"
            vk(1, 2) = "Move " & Chr(10) & "To"
            vk(1, 3) = "SKU"
            vk(1, 4) = "Barcode"
            vk(1, 5) = "Description"
            vk(1, 6) = "Quantity to Transfer"
            k = 1
  For j = 1 To UBound(vg, 2)
    For i = 2 To UBound(vg, 1)
        If vg(i, j) <> "" Then
            If k > 1 Then
                If ve(1, j) = vk(k, 1) Then
                    If vf(1, j) <> vk(k, 2) Then k = k + 1 'insert blank row
                Else
                    k = k + 3 'insert blank row
                    For m = 1 To 6 ' insert header
                        vk(k, m) = vk(1, m)
                    Next
                End If
            End If
                
        k = k + 1
        vk(k, 1) = ve(1, j) 'first store
        vk(k, 2) = vf(1, j) 'second store
        vk(k, 3) = va(i, 1)
        vk(k, 4) = vb(i, 1)
        vk(k, 5) = vc(i, 1)
        vk(k, 6) = vg(i, j)

        End If
    Next
Next

Sheets("Sheet2").Activate 'adjust sheet's name!
Cells.ClearContents
Range("A1").Resize(k, 6) = vk

End Sub
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,286
Members
452,631
Latest member
a_potato

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