VBA to unlink data but keep a copy of file!

Kagzfirearms

New Member
Joined
Nov 15, 2018
Messages
5
Ok so here it is...

I have a pretty complex set of tables strewn across three different sheets. I use my barcode scanner to scan items into a list on one page, It uses that to populate an invoice with data across 3 pages

Page 1 will reference the scanned barcode to find a match on page 3, It populates Price, UPC etc. to fill out the invoice on page 1.

What i am running into is that i have a macro button as follows...

Code:
Sub NextInvoice()
    Range("E4").Value = Range("E4").Value + 1
    Range("sheet3!A2:sheet3!a" & Range("sheet3!A2:sheet3!A518").End(xlDown).Row).Clear
End Sub


Sub SaveInvWithNewName()
    Dim NewFN As Variant
    ' Copy Invoice to a new workbook
    ActiveSheet.Copy
    NewFN = "C:\Users\Kyle\Desktop\PAST INVOICES\Inv" & Range("E4").Value & ".xlsx"
    ActiveWorkbook.SaveAs NewFN, FileFormat:=xlOpenXMLWorkbook
    ActiveWorkbook.Close
    NextInvoice
End Sub

What this does is save a copy of the current sheet as an invoice that i can go back and look at later for any reason, then it refreshes the page and the queries i made by scanning barcodes and it also changes the invoice number on the newly refreshed page.

What i need to do is UNLINK the saved worksheet and keep it from seeing the new data that is entered WHILE keeping the information on the sheet that was saved... I know this sounds horrible but i know you brainiacs know what to do! TIA!!!!
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Problem solved. I just made excel export as PDF to save a copy of it and keep the original form as it was. Code pasted below if that will help anyone.


Code:
Sub NextInvoice()
    Range("E4").Value = Range("E4").Value + 1
    Range("sheet3!A2:sheet3!a" & Range("sheet3!A2:sheet3!A518").End(xlDown).Row).Clear
End Sub
Sub Exportasfixedformat()
    ActiveSheet.Exportasfixedformat Type:=xlTypePDF, filename:="C:\Users\Kyle\Desktop\PAST INVOICES\Inv" & Range("E4").Value _
    , Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
    :=False, OpenAfterPublish:=False
        Printout
        NextInvoice
End Sub


Sub Printout()
    ActiveSheet.Printout preview = False, ignorprintareas = False
End Sub
 
Upvote 0
Problem solved. I just made excel export as PDF to save a copy of it and keep the original form as it was. Code pasted below if that will help anyone.


Code:
Sub NextInvoice()
    Range("E4").Value = Range("E4").Value + 1
    Range("sheet3!A2:sheet3!a" & Range("sheet3!A2:sheet3!A518").End(xlDown).Row).Clear
End Sub
Sub Exportasfixedformat()
    ActiveSheet.Exportasfixedformat Type:=xlTypePDF, filename:="C:\Users\Kyle\Desktop\PAST INVOICES\Inv" & Range("E4").Value _
    , Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
    :=False, OpenAfterPublish:=False
        Printout
        NextInvoice
End Sub


Sub Printout()
    ActiveSheet.Printout preview = False, ignorprintareas = False
End Sub


Where "E4" was the cell containing the invoice number, Sheet3 was the sheet that contained the invoice
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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