Auto generate sales ledger from invoices

Neelie

New Member
Joined
Apr 27, 2019
Messages
10
Ok So this is the first time I've used a forum so please be patient.

I want to generate an invoice in Excel which will update to the next Invoice number when I save it. Also what I need is each time I use a new Invoice I'd like it to be transferred into a Sales Ledger but only using certain fields. Invoice# Date Customer Net amount Tax & Total. So I have an updated list of Invoices.
I have created worksheets Sales Ledger, Sales Invoice, Customers, Stock Codes. I have used VLOOKUP to link the Invoice with Customers & Stock which is working.
I haven't a clue how to write macros and only have basic knowledge of functions.
Hope someone can help. Thank you
 
Click here to download your file. When you click the "Save Invoice" button, the invoice will be saved, the data in the "Sales Invoice" sheet will be copied to the "Sales Invoice Journal" sheet, the invoice number will be increased by 1 and the data cleared for a new entry.
 
Upvote 0

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
@mumps
Can you please post the code the site, as per forum rules
Cheers
 
Upvote 0
@Fluff
My apologies.

Code:
Sub SaveInvoice()
    Application.ScreenUpdating = False
    Dim srcWS As Worksheet, desWS As Worksheet, SubTot As Long
    Set srcWS = Sheets("Sales Invoice")
    Set desWS = Sheets("Sales Invoice Journal")
    SubTot = srcWS.Range("D:D").Find("Subtotal", LookIn:=xlValues, lookat:=xlWhole).Row
    With desWS
        .Cells(.Rows.Count, "A").End(xlUp).Offset(1, 0).Resize(, 7) = Array(Range("F1").Value, Range("B1"), Range("C3").Value, Range("C4").Value, Range("E" & SubTot).Value, Range("E" & SubTot + 1).Value, Range("E" & SubTot + 3).Value)
    End With
    srcWS.Copy
    With ActiveSheet
        .UsedRange.Cells.Value = ActiveSheet.UsedRange.Cells.Value
        .Shapes.Range(Array("Rounded Rectangle 1")).Delete
    End With
    With ActiveWorkbook
        Application.DisplayAlerts = False
        .SaveAs Filename:="C:\Users\Eileen\Desktop\Sales Invoices\" & Range("C4").Value, FileFormat:=51
        Application.DisplayAlerts = True
        .Close False
    End With
    With srcWS
        .Range("B1,B7:B8,B11:B12,C3:C4,D7:D8,E12,F7:F8").SpecialCells(xlCellTypeConstants).ClearContents
        .Range("A16:E" & SubTot - 1).SpecialCells(xlCellTypeConstants).ClearContents
        .Range("F1").Value = .Range("F1").Value + 1
    End With
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
You are very welcome. :) I don't think you can mark as solved on this forum.
 
Upvote 0
OK so I've tried to save the second invoice (first one saved fine) and message says run time error. Debug shows the file path in yellow

Sub SaveInvoice()
Application.ScreenUpdating = False
Dim srcWS As Worksheet, desWS As Worksheet, SubTot As Long
Set srcWS = Sheets("Sales Invoice")
Set desWS = Sheets("Sales Invoice Journal")
SubTot = srcWS.Range("D:D").Find("Subtotal", LookIn:=xlValues, lookat:=xlWhole).Row
With desWS
.Cells(.Rows.Count, "A").End(xlUp).Offset(1, 0).Resize(, 7) = Array(Range("F1").Value, Range("B1"), Range("C3").Value, Range("C4").Value, Range("E" & SubTot).Value, Range("E" & SubTot + 1).Value, Range("E" & SubTot + 3).Value)
End With
srcWS.Copy
With ActiveSheet
.UsedRange.Cells.Value = ActiveSheet.UsedRange.Cells.Value
.Shapes.Range(Array("Rounded Rectangle 1")).Delete
End With
With ActiveWorkbook
Application.DisplayAlerts = False
.SaveAs Filename:="C:\Users\Eileen\Desktop\Sales Invoices" & Range("C4").Value, FileFormat:=51
Application.DisplayAlerts = True
.Close False
End With
With srcWS
.Range("B1,B7:B8,B11:B12,C3:C4,D7:D8,E12,F7:F8").SpecialCells(xlCellTypeConstants).ClearContents
.Range("A16:E" & SubTot - 1).SpecialCells(xlCellTypeConstants).ClearContents
.Range("F1").Value = .Range("F1").Value + 1
End With
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Try replacing that line with this:
Code:
SaveAs Filename:="C:\Users\Eileen\Desktop\Sales Invoices\" & .Sheets("Sales Invoice").Range("C4").Value, FileFormat:=51
 
Upvote 0
Tried to edit but too late!
Feeling embarrassed. Code was fine I'd changed cell for Invoice name so in the code you had C4 I'd entered the name in C3. Sorry
 
Upvote 0
No need to apologize....been there, done that!!!! I'm glad it worked out. :)
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,170
Members
453,021
Latest member
Justyna P

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