coloradoprincess78
New Member
- Joined
- Oct 31, 2016
- Messages
- 14
I borrowed this from another website and customized it to my specific fields, but it does absolutely nothing.
I am inexperienced with vba, I have done simple vba coding but this is by far the most complicated project I've worked on so far, and after a week of messing around, I'm reaching out for help.
Goal - take data from one spreadsheet (shown below) and create individual packing lists using all vba - would like them to be created based off the packing list number as there could be multiple line items shipped (if possible)
The video that relates to this specific coding does exactly what I need, but it just doesn't work for me.
I can accomplish this with a mail merge if this way doesn't work, but prefer using all excel, especially since I am building this for another department to use on a weekly basis.
Can anyone look at my code and see what errors I made please?
My performance review depends on successfully finishing this project
Excel 2010
<tbody>
[TD="align: center"]1[/TD]
[TD="align: center"]2[/TD]
[TD="align: right"]85000[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]3/21/2021[/TD]
[TD="align: right"][/TD]
[TD="align: center"]3[/TD]
[TD="align: right"]85000[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]5/7/2022[/TD]
[TD="align: right"][/TD]
[TD="align: center"]4[/TD]
[TD="align: right"]99999[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]4/12/2021[/TD]
[TD="align: right"][/TD]
</tbody>
I am inexperienced with vba, I have done simple vba coding but this is by far the most complicated project I've worked on so far, and after a week of messing around, I'm reaching out for help.
Goal - take data from one spreadsheet (shown below) and create individual packing lists using all vba - would like them to be created based off the packing list number as there could be multiple line items shipped (if possible)
The video that relates to this specific coding does exactly what I need, but it just doesn't work for me.
I can accomplish this with a mail merge if this way doesn't work, but prefer using all excel, especially since I am building this for another department to use on a weekly basis.
Can anyone look at my code and see what errors I made please?
My performance review depends on successfully finishing this project
Excel 2010
A | B | C | D | E | F | G | H | I | J | K | L | M | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Customer | Address | City | State | Zip | Packing List No. | PO# | Quantity | Item | Description | Serial Number | Expiration Date | Created ? | |
Oasis | 40th Street | Phoenix | AZ | INVTRX00010 | 7777-1 | 889-987 | Sample-987 | 17-987-001 | |||||
Oasis | 40th Street | Phoenix | AZ | INVTRX00010 | 7777-1 | 657-888 | Sample-888 | 17-888-001 | |||||
BigSurf | 18th Ave | Tulsa | OK | INVTRX00011 | 987-123 | 124-342 | Sample-342 | 17-345-001 |
<tbody>
[TD="align: center"]1[/TD]
[TD="align: center"]2[/TD]
[TD="align: right"]85000[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]3/21/2021[/TD]
[TD="align: right"][/TD]
[TD="align: center"]3[/TD]
[TD="align: right"]85000[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]5/7/2022[/TD]
[TD="align: right"][/TD]
[TD="align: center"]4[/TD]
[TD="align: right"]99999[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]4/12/2021[/TD]
[TD="align: right"][/TD]
</tbody>
ShipmentDetails
Code:
Sub PrintPackingList()
'
' PrintPackingList Macro
'
Dim customername As String
Dim customeraddress As String
Dim invoicenumber As Long
Dim r As Long
Dim mydate As String
Dim path As String
Dim myfilename As String
With ActiveSheet
lastrow = .Cells(“A” & Rows.Count).End(xlUp).Row
r = 2
For r = 2 To lastrow
If Cells(r, 12).Value = “done” Then GoTo nextrow
customername = Sheets(“ShipmentDetails”).Cells(r, 1).Value
customeraddress = Sheets(“ShipmentDetails”).Cells(r, 2).Value
city = Sheets(“ShipmentDetails”).Cells(r, 3).Value
State = Sheets(“ShipmentDetails”).Cells(r, 4).Value
zip = Sheets(“ShipmentDetails”).Cells(r, 5).Value
packinglistnumber = Sheets(“ShipmentDetails”).Cells(r, 6).Value
ponumber = Sheets(“ShipmentDetails”).Cells(r, 7).Value
quantity = Sheets(“ShipmentDetails”).Cells(r, 8).Value
Description = Sheets(“ShipmentDetails”).Cells(r, 9).Value
serialnumber = Sheets(“ShipmentDetails”).Cells(r, 10).Value
ExpirationDate = Sheets(“ShipmentDetails”).Cells(r, 11).Value
Cells(r, 12).Value = “done”
Application.DisplayAlerts = False
ChDir "C:\Invoices"
Workbooks.Open Filename:="C:\Packing Lists\Packing List.xlsx"
ActiveWorkbook.Sheets(“PackingList”).Activate
ActiveWorkbook.Sheets(“PackingList”).Range(“T8”).Value = packinglistnumber
ActiveWorkbook.Sheets(“PackingList”).Range(“B12”).Value = customername
ActiveWorkbook.Sheets(“PackingList”).Range(“B13”).Value = customeraddress
ActiveWorkbook.Sheets(“PackingList”).Range(“B14”).Value = city
ActiveWorkbook.Sheets(“PackingList”).Range(“B15”).Value = State
ActiveWorkbook.Sheets(“PackingList”).Range(“B16”).Value = zip
ActiveWorkbook.Sheets(“PackingList”).Range(“D19”).Value = ponumber
ActiveWorkbook.Sheets(“PackingList”).Range(“B22”).Value = quantity
ActiveWorkbook.Sheets(“PackingList”).Range(“D22”).Value = Item
ActiveWorkbook.Sheets(“PackingList”).Range(“J22”).Value = Description
ActiveWorkbook.Sheets(“PackingList”).Range(“R22”).Value = serialnumber
ActiveWorkbook.Sheets(“PackingList”).Range(“W22”).Value = ExpirationDate
path = "C:\Packing Lists\"
mydate = Date
mydate = Format(mydate, “mm_dd_yyyy”)
ActiveWorkbook.SaveAs Filename:=path & packinglistnumber & “ - ” & customername & “ - ” & mydate & “.xlsx”
myfilename = ActiveWorkbook.FullName
SetAttr myfilename, vbReadOnly
Application.DisplayAlerts = True
ActiveWorkbook.PrintOut copies:=1
ActiveWorkbook.Close SaveChanges:=False
nextrow:
Next r
End With
End Sub