Paula
Paula

Reputation: 229

Date in VBA form

On my excel form I would like for my date to auto populate with today's date, I tried using the =Today() function but when I submitted after filling out the form it only appears to update it once.I need it to work each time I press the submit button. Any help/advice anyone could give would be greatly appreciated.

Many Thanks Paula

Upvotes: 0

Views: 2146

Answers (2)

HavelTheGreat
HavelTheGreat

Reputation: 3386

Once again, I would recommend using a UserForm! Then in the code for that form, you can simply insert:

Private Sub UserForm_Initialize() Project.MyTxtBox = Date End Sub

I would recommend this resource for learning more about the possibilities of UserForms.

Edit: If you want to populate on the Submit button, you must find the initialization procedure for the click on that button. It will end in .._Click(). Within that procedure you will have to add Project.MyTxtBox = Date and you should be good to go.

Upvotes: 1

TEC C
TEC C

Reputation: 153

If your looking for this in VBA you would select your Developer tab, click on Visual Basic, create a new method, then paste this code in.

    Sub tDate()
Range("A1") = Date
End Sub

after that link the button to the macro you just created. Every time the macro runs it will give you the current date.

Upvotes: 0

Related Questions