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
 
@jay_hl, try this:
I put the result in sheet2.
VBA Code:
Sub jay_hl_1()
Dim i As Long, j As Long, n As Long, k As Long, p As Long
Dim va, vb, vc

n = Range("A" & Rows.Count).End(xlUp).Row
va = Range("A5:A" & n)
p = Cells(5, "CO").End(xlToLeft).Column
vb = Range(Cells(5, "BF"), Cells(n, p))
ReDim vc(1 To 500000, 1 To 4)
For j = 1 To UBound(vb, 2)
    For i = 2 To UBound(vb, 1)
        If vb(i, j) > 0 Then
            k = k + 1
            vc(k, 1) = vb(1, j)
            vc(k, 2) = va(i, 1)
            vc(k, 3) = "PCS"
            vc(k, 4) = vb(i, j)
        End If
    Next
Next

'put the result in sheet2
Sheets("Sheet2").Activate
Range("A:D").ClearContents
Range("A3").Resize(k, 4) = vc

End Sub

In your example in post #9, Range H5:K5 is really blank, right? there is no word "(blank)" in it?
Thanks so much. This works really well, apart from one challenge, which is that it only seems to work for the first store.

I think thats because the variable p isnt setting the right end column, because it seems store name headers are "" and not really truley empty cells. Is there a change we can set p to equal alphanumberic characters, or a length over 2 characters or something like that?
 
Upvote 0

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
I think thats because the variable p isnt setting the right end column, because it seems store name headers are "" and not really truley empty cells.
Are you saying store name headers are result of formula?
 
Upvote 0
Try this one:

Rich (BB code):
Sub jay_hl_2()
Dim i As Long, j As Long, n As Long, k As Long, p As Long
Dim va, vb, vc
'BF5:CN5
n = Range("A" & Rows.Count).End(xlUp).Row
va = Range("A5:A" & n)
p = Range("BF5:CN5").Find(What:="*", LookIn:=xlValues, lookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlPrevious, MatchCase:=False, SearchFormat:=False).Column

vb = Range(Cells(5, "BF"), Cells(n, p))
ReDim vc(1 To 500000, 1 To 4)
For j = 1 To UBound(vb, 2)
    For i = 2 To UBound(vb, 1)
        If vb(i, j) > 0 Then
            k = k + 1
            vc(k, 1) = vb(1, j)
            vc(k, 2) = va(i, 1)
            vc(k, 3) = "PCS"
            vc(k, 4) = vb(i, j)
        End If
    Next
Next

'put the result in sheet2
Sheets("Sheet2").Activate
Range("A:D").ClearContents
Range("A3").Resize(k, 4) = vc

End Sub
 
Upvote 1
Solution
Try this one:

Rich (BB code):
Sub jay_hl_2()
Dim i As Long, j As Long, n As Long, k As Long, p As Long
Dim va, vb, vc
'BF5:CN5
n = Range("A" & Rows.Count).End(xlUp).Row
va = Range("A5:A" & n)
p = Range("BF5:CN5").Find(What:="*", LookIn:=xlValues, lookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlPrevious, MatchCase:=False, SearchFormat:=False).Column

vb = Range(Cells(5, "BF"), Cells(n, p))
ReDim vc(1 To 500000, 1 To 4)
For j = 1 To UBound(vb, 2)
    For i = 2 To UBound(vb, 1)
        If vb(i, j) > 0 Then
            k = k + 1
            vc(k, 1) = vb(1, j)
            vc(k, 2) = va(i, 1)
            vc(k, 3) = "PCS"
            vc(k, 4) = vb(i, j)
        End If
    Next
Next

'put the result in sheet2
Sheets("Sheet2").Activate
Range("A:D").ClearContents
Range("A3").Resize(k, 4) = vc

End Sub
This works amazingly well. Thanks so much.

Jay
 
Upvote 0
You're welcome, glad to help & thanks for the feedback.:)
 
Upvote 0
Hello

Ive been using your code, and have now adapted it to a new set up, which was working really when the array is formed as single continuous list. However there are two improvements that I need to make around formatting that I cant get to work. So wonder if you could help.

The first change is rather than a continuous list across all rows, I need the output as 4 "tables". When the value in the first column changes (e.g from Store 1 to Store 2) I need to insert two blank rows and then the the Header Row, which is hard coded in the first line of the array.

The second change if that I need to create a blank row, when the value in the second column changes.

I have pasted my current code below, but wondered if I can get some help with what im trying to achieve. There is also a screenshot of what I an trying to achieve with sample data.


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)
For j = 1 To UBound(vg, 2)
            vk(1, 1) = "Move From"
            vk(1, 2) = "Move To"
            vk(1, 3) = "SKU"
            vk(1, 4) = "Barcode"
            vk(1, 5) = "Description"
            vk(1, 6) = "Quantity to Transfer"
    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



Appreciate the help

Jay
 
Upvote 0
Could you please provide some example data along with the expected results? Please use the XL2BB tool to post your example, so we don't have to retype it.

OR

Could you please upload a sample workbook to a file-sharing site like Dropbox or Google Drive and share the link here? Also, ensure that the link is accessible to anyone. If there is sensitive data, please replace it with representative dummy data. And please also provide the expected results.
 
Upvote 0
Move FromMove ToSKUBarcodeDescriptionQuantity to Transfer
Store 1Store 211875067953400Desc 110
Store 1Store 225084518301741Desc 210
Store 1Store 334799819599110Desc 36
Store 1Store 346599293610642Desc 46
Store 1Store 453706617638861Desc 66
Store 1Store 469613100809367Desc 715
Store 1Store 472632382363493Desc 88
Store 1Store 483767648862077Desc 98
Store 1Store 498542774622658Desc 108
Store 1Store 4106340813069086Desc 1114
Store 1Store 4118559955993466Desc 127
Store 1Store 4124648033359110Desc 1317
Store 1Store 4138264023743408Desc 1410
Move FromMove ToSKUBarcodeDescriptionQuantity to Transfer
Store 2Store 113588712844609Desc 112
Store 2Store 323585632196472Desc 26
Store 2Store 339594754496193Desc 36
Store 2Store 441642495585470Desc 412
Store 2Store 465678830664994Desc 515
Store 2Store 477014042320179Desc 67
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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