[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Help on Excel formula to increase invoice number based on date change

Posted on 2013-01-08
7
Medium Priority
?
911 Views
Last Modified: 2013-02-18
I have an excel spreadsheet that I use for invoicing a client.  I would like to create an "if then" formula so that when a date changes in one of the cells, the cell that contains the invoice number will increment by 1.

For example, my date is 01/01/2013 and my invoice number is 2013-001.  What I would like to happen is that anytime the date changes, the invoice will automatically update, so if the next time I open this file and the date changes to 01/04/2013 then I would like the invoice number to automatically update to 2013-002, hopefully this makes sense, thank you.
0
Comment
Question by:WJM
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 32

Accepted Solution

by:
Robberbaron (robr) earned 2000 total points
ID: 38757503
yes this makes sense as i do something very similar.

What it requires is a hidden cell to hold the date the last time the invoice was updated.  I use a Status sheet that is hidden.

Does the cell with date automatically update when the workbook is opened, or is this something the user does ?   This determines the method we use to check for date change.
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
    If Target.Address = Range("Newdate").Address Then
        'date was changed
        GetInvoice
    End If
End Sub

Open in new window

Sub GetInvoice()
    Dim Prevdate As Date, NewDate As Date, PrevInv As Integer
    Dim newInv As Integer
    NewDate = Range("Newdate").Value
    Prevdate = Range("Prevdate").Value
    PrevInv = Range("PrevInv").Value
       
    If NewDate > Prevdate Then
        'this is a new invoice
        If Year(NewDate) = Year(Prevdate) Then
            'use next number
            newInv = PrevInv + 1
         Else
            newInv = 1
        End If
        
        'update the saved data
       Range("Prevdate").Value = NewDate
       Range("PrevInv").Value = newInv
     Else
        newInv = PrevInv
        
    End If
    
    Range("Invoice").Value = Format(NewDate, "yyyy-") & Format(newInv, "000")
    
    
        
End Sub

Open in new window

sample-invoice.xls
0
 

Author Comment

by:WJM
ID: 38761291
Yes, that's it baron; however, how do I get the Sub codes to work properly, I'm not an expert at Excel and though I see how the cells are working in your sample you provide I do not know how to duplicate that in my Excel file, thank you.
0
 
LVL 32

Expert Comment

by:Robberbaron (robr)
ID: 38761430
you need to open the devloper tab.  Copy and paste the code in to your workbook.

The Workbook_SheetChange sub goes into the Workbook object.
Need to create a user module for the other code. (one way is to record a macro).

And then create the named ranges to suit your workbook.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Expert Comment

by:tweakmasters
ID: 38766232
There are few more thing that need to be clarified before your can apply a good patch for your problem. Can you please clarify if you have only one sheet where you want the number changed accordingly to date or do you open multiple sheets (do you keep or discard previous invoice records)? From your description seems like you don't keep previous records.
0
 

Author Comment

by:WJM
ID: 38780157
tweakmasters, it is only one sheet.  I update that sheet, save it, save to PDF and close, the next week I open up the previous weeks excel file, update it with the current weeks information and do the save and close process again.  Records are kept as PDF's but the Excel file is always updated...
0
 
LVL 32

Expert Comment

by:Robberbaron (robr)
ID: 38781249
my invoice workbook is surprisingly similar. I have done the PDF creation as a macro that saves the PDF with a date in filename.
0
 

Author Closing Comment

by:WJM
ID: 38901716
Thank you very much.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question