+ Reply to Thread
Results 1 to 7 of 7

Macro to generate invoice

  1. #1
    Registered User
    Join Date
    04-19-2011
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    33

    Red face Macro to generate invoice

    Hi guys

    I hope one of your geniuses can help me cut down on my time. Its so manual this process.

    In column U I have the "Yes" and "NO". This is what the macro will then loop through ALL the rows with "YES".

    If YES then:

    First the macro should lookup column J value in the SUPPLIERDB worksheet to get the full address and put this on the invoice worksheet where it starts "Supplier Name".
    Then the macro join firstname and surname to get the value and then use this value to lookup the CLIENTDB with the address details.

    Arrival Date Column D in bookings should be copied to "Arrival Date" column on row 19
    Expected Departure Column E in bookings should be copied to "Expected Departure" column on row 19
    Total number nights Column F in bookings should be copied to "# of nights"
    Price/night in column K in bookings should be copied to "Price/night"

    Previously invoiced for column G in bookings should be copied to D26
    Remaining nights to invoice Column H in bookings should be copied to D27

    Net comm column O in bookings should be copied to I22

    A PDF should then be generated and saved to the following location:

    C:/apartmentinvoices

    Please see attached my sample excel worksheet for you to see what I am trying to achieve which is to automate my invoice generation process.
    Attached Files Attached Files

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,428

    Re: Macro to generate invoice

    I would suggest that you record a macro while you carry out the actions manually. Once you have the basic code to create an invoice, you can then loop through the column(s) as required for subsequent details and/or invoices.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Macro to generate invoice

    This is how I would do this. On your invoice I created control cells in N1, N2 and O1. Then I added formulas all through your invoice to draw in the data you want based the values in N1. O1 updates itself as well.

    This way, you can review any invoice you'd like by simply entering a row number in N1. This also means your macro will need minimal editing in the future. If you decide to change your Invoice layout, then you do that on the Invoice formulas, not in the macro.

    Two comments, you didn't indicate what the PDF filename should be, so I opted to use the ClientName in C12 along with today's code number.
    JohnDoe-42658.pdf

    Also, the Invoice Number field was not addressed, so I added it another control in N2. For now it increments each time the macro puts a new row number in N1. I'm not sure this is the best approach, since you might print Invoices for the same client/event several times, we should probably consider keeping the Invoice # the same. For that, I would suggest another column on the Bookings tab called INVOICE NUMBER. You can manually assign an invoice code to each row, or we can have the macro do it... the first time a row is invoiced the macro could detect this field was empty and assign the next number permanently.

    After that, this simple macro should do what you want:
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by JBeaucaire; 10-16-2016 at 06:26 PM.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  4. #4
    Registered User
    Join Date
    04-19-2011
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    33

    Re: Macro to generate invoice

    Thanks so much for taking the time to do all that so fast!

    It seems to be breaking on this section of the code:

    Please Login or Register  to view this content.
    Last edited by JBeaucaire; 10-15-2016 at 01:24 PM.

  5. #5
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Macro to generate invoice

    I removed the whole-post from your message above, that's just clutter. Use the Quick REPLY box below. Or, just quote the section you want to discuss.

    I also added code tags to the code you quoted, as per forum rules. Always use code tags for readability. Thanks.

    I just ran the code and got a whole folder full of PDFs. I can only guess why it's not working for you. Does the output folder exist?

  6. #6
    Registered User
    Join Date
    04-19-2011
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    33

    Re: Macro to generate invoice

    Hi there

    I just ran it again, it does save the PDFs, thanks but it doesn't save them in the relevant folder. Its saves them in my documents.

    Any way to fix?

    Cheers for your help.

  7. #7
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Macro to generate invoice

    Oops! My Bad. Code corrected above in post #3, forgot to include the fPATH in the filename.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Auto invoice generate number with Save as PDF Macro with
    By Tai1001 in forum Excel Programming / VBA / Macros
    Replies: 20
    Last Post: 04-12-2015, 10:23 AM
  2. [SOLVED] Generate an invoice from a cost summary
    By bigtiger1 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 10-14-2014, 01:20 PM
  3. Macro to automatically generate invoice number
    By Tahya in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-13-2014, 04:39 PM
  4. I need a macro that will create a new sheet, generate invoice number
    By Daotor in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-05-2013, 09:20 AM
  5. How do I generate an atomated invoice from my invoice register?
    By Daotor in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-23-2013, 06:47 AM
  6. [SOLVED] How do I generate a new invoice number when creating new invoice?
    By KiddieWonderland in forum Excel General
    Replies: 1
    Last Post: 03-14-2006, 11:20 PM
  7. Automating to generate the next Invoice No.
    By Murad Sheikh in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-10-2005, 11:05 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1