PDA

View Full Version : Invoice date help



stace224
01-02-2018, 11:47 AM
Hi everyone

I'm new to the forums :hi: 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... :think:

Paul_Hossler
01-02-2018, 01:21 PM
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

SamT
01-02-2018, 01:38 PM
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