VBA to extract specific data from sheet 1 to transfer into sheet 2

George1

New Member
Joined
Jun 26, 2009
Messages
13
Hi there, I currently have a master invoice template that I use for invoicing customers. I have put some automation on this such as next invoice and save as pdf to a particular drive. I am looking to capture specific data from the invoice template, when I click the "save to PDF" button, to capture invoice date, invoice number, supplier, goods description, sub total, VAT and Gross amount and save these particular bits of data to an invoice details sheet that I will hold on the same workbook to track suppliers and invoices at a glance. Any suggestions would be appreciated. Regards G1.
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
You don't have a column for the Invoice Number in the "Invoice Details" sheet. Insert a new column B to the right of the "Date" column and name it "Invoice #". Replace the current macro that saves to PDF by the one below:

Code:
Sub SavePDF()
    Dim LastRow As Long
    LastRow = Sheets("Invoice Details").Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row + 1
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
        Filename:="C:\Users\sheeh\Documents\Suppliers\Invoice_" & _
        ActiveSheet.Range("F9").Value & ".pdf", _
        OpenAfterPublish:=True
    Sheets("Invoice Details").Cells(LastRow, 1).Resize(1, 6) = Array(Range("F10").Value, Range("F9").Value, Range("B9").Value, Range("G41").Value, Range("G42").Value, Range("G43").Value)
End Sub

Hi there,
You kindly helped me out with the VBA coding above recently. The button to saved to a PDF was picking up the invoice number and customer name and putting these into the title of the file but I've just noticed that when the file is saved, it does not pick up the supplier name in cell "B9". I've tried amending the range to include B9 along with F9 (Invoice number) but I keep getting an error. If you have any suggestions how I could fix this please? Regards G1.
 
Upvote 0
Get back soon.
 
Last edited:
Upvote 0
Try:
Code:
Sub SavePDF()
    Dim LastRow As Long
    LastRow = Sheets("Invoice Details").Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row + 1
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
        Filename:="C:\Users\sheeh\Documents\Suppliers\Invoice_" & ActiveSheet.Range("B9").Value & ActiveSheet.Range("F9").Value & ".pdf", OpenAfterPublish:=True
    Sheets("Invoice Details").Cells(LastRow, 1).Resize(1, 6) = Array(Range("F10").Value, Range("F9").Value, Range("B9").Value, Range("G41").Value, Range("G42").Value, Range("G43").Value)
End Sub
 
Upvote 0
Try:
Code:
Sub SavePDF()
    Dim LastRow As Long
    LastRow = Sheets("Invoice Details").Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row + 1
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
        Filename:="C:\Users\sheeh\Documents\Suppliers\Invoice_" & ActiveSheet.Range("B9").Value & ActiveSheet.Range("F9").Value & ".pdf", OpenAfterPublish:=True
    Sheets("Invoice Details").Cells(LastRow, 1).Resize(1, 6) = Array(Range("F10").Value, Range("F9").Value, Range("B9").Value, Range("G41").Value, Range("G42").Value, Range("G43").Value)
End Sub

Thank you
icon14.png
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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