Consulting

Results 1 to 3 of 3

Thread: Invoice date help

  1. #1

    Invoice date help

    Hi everyone

    I'm new to the forums and was hoping someone had a solution to my problem.

    I have invoices that I was hoping to make the date update automatically to save inserting the date when filling in an invoice however the formula I've used updates each time the file is opened (I used =Today() ) which would make sense. I'm looking to see if it is possible to save me typing in the date when I fill in a new invoice (create about 20 per month - not daily) that would not update the next time the file is opened. (The files need to be accessed for audit purposes)

    Hope this makes sense...

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,738
    Location
    The easiest way I know is to have a workbook open event

    If there is something in the "Date Of" field, it leaves it; otherwise it enters today


    Option Explicit
    
    Private Sub Workbook_Open()
        Dim x As Long
        
        'see if WS Invoice is there
        x = -1
        On Error Resume Next
        x = Worksheets("Invoice").Index
        On Error GoTo 0
        
        If x = -1 Then Exit Sub
        
        
        With Worksheets("Invoice")
            If Len(.Range("B3").Value) = 0 Then .Range("B3").Value = Format(Date, "yyyy-mm-dd")
        End With
    End Sub
    Attached Files Attached Files
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  3. #3
    VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    Paul's is an excellent, fool proof method of using the Workbook open event.
    Here's one for just the Invoice sheet
    Option Explicit
    
    Private Sub Worksheet_Activate()
    If IsDate(Range("B3")) Then Exit Sub
    Range("B3") = Format(Date, "d MMM, yyyy")
    End Sub
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

Posting Permissions

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