VBA to auto count Invoice number, transfer invoice data to ledger

Jnb99

Board Regular
Joined
Mar 29, 2016
Messages
84
Hi everyone,

I have a workbook with the below code. Everything works fine thanks to @rlv01 .

Next I would like to have the estimate number increase +1 every time the macro is run. I've added code for this but not sure where to add it in the order. Estimate number is in "F4" - Sheet "Estimate"
I would also like to transfer main info from the estimate to a database (sheet "Estimate database")
Data to be transferred:

CELL:
Date F3
Estimate number F4
Client A14
Total G44

VBA Code:
Private Sub CommandButton1_Click()
    Dim saveLocation As String
    Dim rng As Range

    saveLocation = "C:\Users\***\Estimates\" & Range("f4").Value & Range("a14").Value & ".pdf"
    
    Set rng = Worksheets("Estimate").Range("A1:g50")
    rng.ExportAsFixedFormat Type:=xlTypePDF, Filename:=saveLocation
    Worksheets("Estimate").Range("A23:a41").ClearContents
    Call saveSheetWithoutFormulas
    
End Sub

Sub saveSheetWithoutFormulas()
   Dim saveLocation As String, xlsxFile  As String
    Dim WB As Workbook, WS As Worksheet
    Dim SheetName As String
    
    SheetName = ActiveSheet.Name
    
    saveLocation = "C:\Users\***\Estimates\" & ActiveSheet.Range("f4").Value & Range("a14").Value
    xlsxFile = Split(saveLocation, ".")(0) & ".xlsx"
    
    Application.DisplayAlerts = False
    ThisWorkbook.SaveCopyAs Filename:=saveLocation
    
    Set WB = Application.Workbooks.Open(Filename:=saveLocation)
    Set WS = WB.Worksheets(SheetName)
    WS.UsedRange.Value = WS.UsedRange.Value

    WB.saveas Filename:=xlsxFile, FileFormat:=xlOpenXMLWorkbook    'see XlFileFormat Enumeration for different formats
    WB.Close False
    Application.DisplayAlerts = False
        
    Kill saveLocation
End Sub
Sub NextInvoice()
    Range("f4").Value = Range("f4").Value + 1
End Sub

Thanks
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.

Forum statistics

Threads
1,214,585
Messages
6,120,397
Members
448,957
Latest member
Hat4Life

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