Create a list from certain cells

Trueblue862

Board Regular
Joined
May 24, 2020
Messages
160
Office Version
  1. 365
Platform
  1. Windows
Hi, this is only my second thread, thankyou for the great help I received in the first one.

I'm helping a friend set up a home delivery fruit and veg business and I'm up to my final stage in this project, I need to generate a picking list from my invoice. When I finalise the invoice I need it to copy across the products and quantity of each along with the delivery address and invoice number to aid with packing products into the correct box. Then if it's not too difficult I need to sort by product. I'm well out of my depth on this project, but have welcomed the challenge it has presented. It has been a very steep learning curve, but I can't help but feel I really need to do a course on VBA to do it effectivly.

This is the code I have at the moment, I've adapted it from something I found online.
I'm not fluent enough in coding to see where it's wrong.
Any help would be greatly appreciated.
VBA Code:
Sub PackingList()
Dim InvoiceNumber As Integer
Dim Description As String
Dim Address As String
Dim Quantity As Integer
Dim cVal As String, rVal As String
Dim fCol As Range, fRow As Range, cl As Range
Dim Ws As Worksheet
      Set Ws = Worksheets("Invoice").Select
         InvoiceNumber = Ws.Range("E4")
            Description = Ws.Range("C14:C33")
               Quantity = Ws.Range("B14:B33")
                  Address = Ws.Range("B8")
            Worksheets("Packing List").Select
         Worksheets("Packing List").Range("A1").Select
     If Worksheets("Packing List").Range("A1").Offset(1, 0) <> "" Then
    Worksheets("Packing List").Range("A1").End(x1Down).Select
End If
    ActiveCell.Offset(1, 0).Select
    ActiveCell.Value = InvoiceNumber
End Sub

This is my invoice


Ordering Sheet ver 2.xlsm
ABCDEFGHIJ
1Ward's ProduceINVOICE
2somebody@outlook.comABN: 99 999 999 999
3Sometown, QldDATE:May 31, 2020
44650INVOICE #163
5Phone: 1111 111 111
6Bill To:
7Delivery Details0
8 
9 
10 
110000000000
12
13QuantityDESCRIPTIONUnit PriceAMOUNT
14  $ -
15  $ -
16  $ -
17  $ -
18  $ -
19  $ -
20  $ -
21  $ -
22  $ -
23  $ -
24  $ -
25  $ -
26  $ -
27  $ -
28  $ -
29  $ -
30  $ -
31  $ -
32  $ -
33  $ -
34 SUBTOTAL $ -
35 DELIVERY
36 TOTAL $ -
37
38THANK YOU FOR YOUR BUSINESS!
39
40
41
42
Invoice
Cell Formulas
RangeFormula
E3E3=TODAY()
E7E7=IFERROR(XLOOKUP(B7,Table2[[#All],[Customer Name]],Table2[[#All],[Delivery Day]]),"")
B8B8=IFERROR(XLOOKUP(B7,Table2[[#All],[Customer Name]],Table2[[#All],[Address]]),"")
B9B9=IFERROR(XLOOKUP(B7,Table2[[#All],[Customer Name]],Table2[[#All],[City]]),"")
B10B10=IFERROR(XLOOKUP(B7,Table2[[#All],[Customer Name]],Table2[[#All],[Postcode ]]),"")
B11B11=IFERROR(XLOOKUP(B7,Table2[[#All],[Customer Name]],Table2[[#All],[Phone Number]]),"")
D14:D17D14=IFERROR(XLOOKUP([@DESCRIPTION],Sheet1!C1:C98,Sheet1!B1:B98),"")
D18D18=IFERROR(XLOOKUP([@DESCRIPTION],Sheet1!C4:C101,Sheet1!B4:B101),"")
D19D19=IFERROR(XLOOKUP([@DESCRIPTION],Sheet1!C4:C101,Sheet1!B4:B101),"")
D20D20=IFERROR(XLOOKUP([@DESCRIPTION],Sheet1!C4:C101,Sheet1!B4:B101),"")
D21D21=IFERROR(XLOOKUP([@DESCRIPTION],Sheet1!C4:C101,Sheet1!B4:B101),"")
D22D22=IFERROR(XLOOKUP([@DESCRIPTION],Sheet1!C4:C101,Sheet1!B4:B101),"")
D23D23=IFERROR(XLOOKUP([@DESCRIPTION],Sheet1!C4:C101,Sheet1!B4:B101),"")
D24D24=IFERROR(XLOOKUP([@DESCRIPTION],Sheet1!C4:C101,Sheet1!B4:B101),"")
D25D25=IFERROR(XLOOKUP([@DESCRIPTION],Sheet1!C4:C101,Sheet1!B4:B101),"")
D26D26=IFERROR(XLOOKUP([@DESCRIPTION],Sheet1!C4:C101,Sheet1!B4:B101),"")
D27D27=IFERROR(XLOOKUP([@DESCRIPTION],Sheet1!C4:C101,Sheet1!B4:B101),"")
D28D28=IFERROR(XLOOKUP([@DESCRIPTION],Sheet1!C4:C101,Sheet1!B4:B101),"")
D29D29=IFERROR(XLOOKUP([@DESCRIPTION],Sheet1!C4:C101,Sheet1!B4:B101),"")
D30D30=IFERROR(XLOOKUP([@DESCRIPTION],Sheet1!C4:C101,Sheet1!B4:B101),"")
D31D31=IFERROR(XLOOKUP([@DESCRIPTION],Sheet1!C4:C101,Sheet1!B4:B101),"")
D32D32=IFERROR(XLOOKUP([@DESCRIPTION],Sheet1!C4:C101,Sheet1!B4:B101),"")
D33D33=IFERROR(XLOOKUP([@DESCRIPTION],Sheet1!C4:C101,Sheet1!B4:B101),"")
E14:E33E14=PRODUCT([@[Unit Price]],[@Quantity])
E34E34=SUBTOTAL(109,[AMOUNT])
E35E35=IFERROR(LOOKUP(Invoice[[#Totals],[AMOUNT]],{25;40},7),"")
E36E36=SUM(E34:E35)
Named Ranges
NameRefers ToCells
Sheet1!Print_Area=Sheet1!$C:$C,Sheet1!$E:$E,Sheet1!$G:$G,Sheet1!$I:$I,Sheet1!$K:$ND14



This is my packing list

Ordering Sheet ver 2.xlsm
ABCDE
1DescriptionQuantity UnitInvoice NumberAddress
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
Packing List
Cells with Data Validation
CellAllowCriteria
A2List=Sheet1!$Y$1#
 
Last edited by a moderator:
This sub adds the invoice to the packing list. Call it when needed. Please test on a copy of your workbook.
VBA Code:
Sub PackingList()
    Dim Description As String
    Dim Quantity    As Integer
    
    Dim invoiceRow  As Long
    Dim packlistRow As Long
    
    Dim Ws As Worksheet
    Set Ws = Worksheets("Invoice")
    
    Dim pl As Worksheet
    Set pl = Worksheets("Packing List")
    
    Dim invoiceNumber As Integer
    invoiceNumber = Ws.Range("E4")
    
    Dim Address As String
    Address = Ws.Range("B8")
    
    'Set packlist row to the first available
    packlistRow = pl.Range("A1000").End(xlUp).Row + 1

    invoiceRow = 14
    
        Description = Ws.Cells(invoiceRow, 3)
        Quantity = Ws.Cells(invoiceRow, 2)
    While (Description > "") And (invoiceRow < 34)
        pl.Cells(packlistRow, 1).Value = Description
        pl.Cells(packlistRow, 2).Value = Quantity
        pl.Cells(packlistRow, 4).Value = invoiceNumber
        pl.Cells(packlistRow, 5).Value = Address
        
        invoiceRow = invoiceRow + 1
        packlistRow = packlistRow + 1
        
        Description = Ws.Cells(invoiceRow, 3)
        If Description > "" Then Quantity = Ws.Cells(invoiceRow, 2)
    Wend
    
End Sub
 
Upvote 0

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type

Forum statistics

Threads
1,223,911
Messages
6,175,324
Members
452,635
Latest member
laura12345

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