+ Reply to Thread
Results 1 to 4 of 4

Invoice Macro Problem

Hybrid View

  1. #1
    Registered User
    Join Date
    11-02-2013
    Location
    Australia
    MS-Off Ver
    Excel 2007
    Posts
    2

    Invoice Macro Problem

    I have a very simple macro that I found on the internet that increases an invoice number by 1.

    Sub NextInvoice()

    Range("L1").Value = Range("L1").Value + 1

    End Sub

    It works great, provided the invoice number is just numbers. But I want to be able to add PF as in PF101425, on some of the invoices, not every invoice, however when I put the PF there the macro does not work.

    There is more to the macro than just increasing the invoice number. It also populates other cells on a separate sheet with the information from the invoice and then clears all fields ready for the next invoice. So when I click on the button that triggers the macro the fields are populated correctly, even with the PF in front of the number, it is just the invoice number does not increase by 1.

    If anybody can help with this problem it would be appreciated. Thank you.

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Invoice Macro Problem

    Hi, aussieExcel,

    you should assign the prefix to a different cell and concatenate those values for the invoice.

    Sub NextInvoice()
    
    Const cstrPRE As String = "PF"
    
    With Range("L1")
      If IsNumeric(.Value) Then
        .Value = .Value + 1
      Else
        .Value = cstrPRE & Mid(.Value, Len(cstrPRE) + 1) + 1
      End If
    End With
    
    End Sub
    Please note that you should wrap your procedure with code-tags when showing it here on ExcelForum.

    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  3. #3
    Registered User
    Join Date
    11-02-2013
    Location
    Australia
    MS-Off Ver
    Excel 2007
    Posts
    2

    Re: Invoice Macro Problem

    Hello Holger,

    Thank you. It works perfectly. Sorry about not using the code tags.


    Kathleen

  4. #4
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,692

    Re: Invoice Macro Problem

    I was thinking more like

    Sub Maybe_This()
        Dim invnr As Long, rep As Byte
        If Left([L1], 2) = "PF" Then
            invnr = Mid([L1], 3, 15)    'Max 17 characters for invoice number
        Else
            invnr = [L1]
        End If
        rep = MsgBox("Do you want PF with the invoive number?", vbYesNo + vbCritical)
        If rep = vbYes Then
            [L1] = "PF" & invnr + 1
        Else
            [L1] = invnr + 1
        End If
    End Sub
    This will give you the option of using "PF" or not (on some of the invoices, not every invoice)
    Last edited by jolivanes; 11-04-2013 at 02:35 AM. Reason: add to option

+ 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. Save invoice problem
    By smarko1983 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-10-2013, 11:15 AM
  2. Replies: 4
    Last Post: 11-04-2012, 12:43 PM
  3. Invoice number problem
    By zplugger in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-09-2011, 06:22 AM
  4. Macro problem X2 on invoice
    By benswelding in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-03-2010, 07:41 AM
  5. invoice problem
    By lsent in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 03-20-2006, 03:25 PM

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