Hi, am struggling with Macros from podcast 1505 and 1808. Here, a macro is written to do the following:
1. generate the next invoice number
2. clear certain fields ready for next invoice data to be filled in
3. save workbook with a unique name to specific folder on C drive
4. carry key data from each invoice through to invoice register.
Points 1, 2, 4 work fine but point 3 I am struggling with. It doesn't save with a unique number so when I draft a new invoice I am required to save over the previously saved worksheet. Here is the code as I have it, I really hope someone can point me the right direction :
Sub PostToRegister()
Dim WS1 As Worksheet
Dim WS2 As Worksheet
Set WS1 = Worksheets("Invoice")
Set WS2 = Worksheets("Register")
' Figure out which row is the next row
NextRow = WS2.Cells(Rows.Count, 1).End(xlUp).Row + 1
' Write the important values to register
WS2.Cells(NextRow, 1).Resize(1, 8).Value = Array(WS1.Range("K16"), WS1.Range("H16"), WS1.Range("B16"), WS1.Range("B22"), WS1.Range("N16"), WS1.Range("O48"), WS1.Range("O52"), WS1.Range("V25"))
End Sub
Sub NextInvoice()
Range("K16").Value = Range("K16").Value + 1
Range("V3:W21").ClearContents
End Sub
Sub SaveWithNewName()
Dim NewFN As Variant
PostToRegister
' Copy Invoice to a new workbook
ActiveSheet.Copy
NewFN = "C:\Users\User\Dropbox\Evergen - Invoices\Sales Invoices" & Range("K16").Value & ".xlsx"
ActiveWorkbook.SaveAs NewFN, xlOpenXMLWorkbook
ActiveWorkbook.Close
NextInvoice
End Sub
1. generate the next invoice number
2. clear certain fields ready for next invoice data to be filled in
3. save workbook with a unique name to specific folder on C drive
4. carry key data from each invoice through to invoice register.
Points 1, 2, 4 work fine but point 3 I am struggling with. It doesn't save with a unique number so when I draft a new invoice I am required to save over the previously saved worksheet. Here is the code as I have it, I really hope someone can point me the right direction :
Sub PostToRegister()
Dim WS1 As Worksheet
Dim WS2 As Worksheet
Set WS1 = Worksheets("Invoice")
Set WS2 = Worksheets("Register")
' Figure out which row is the next row
NextRow = WS2.Cells(Rows.Count, 1).End(xlUp).Row + 1
' Write the important values to register
WS2.Cells(NextRow, 1).Resize(1, 8).Value = Array(WS1.Range("K16"), WS1.Range("H16"), WS1.Range("B16"), WS1.Range("B22"), WS1.Range("N16"), WS1.Range("O48"), WS1.Range("O52"), WS1.Range("V25"))
End Sub
Sub NextInvoice()
Range("K16").Value = Range("K16").Value + 1
Range("V3:W21").ClearContents
End Sub
Sub SaveWithNewName()
Dim NewFN As Variant
PostToRegister
' Copy Invoice to a new workbook
ActiveSheet.Copy
NewFN = "C:\Users\User\Dropbox\Evergen - Invoices\Sales Invoices" & Range("K16").Value & ".xlsx"
ActiveWorkbook.SaveAs NewFN, xlOpenXMLWorkbook
ActiveWorkbook.Close
NextInvoice
End Sub