How do I write a VB code for a 'Date' text box for spreadsheet

G

Guest

I am having difficulties in creating a VB code for a 'Parts Inventory'
spreadsheet.
In my 'Userform' in Visual Basic I have a text box used for entering a date
as a number eg. 290906 which will then enter in the 'Parts Inventory'
spreadsheet as 29/09/06. Does anyone know what the code is or how to do it? I
was told it had something to do with YEAR: function??? Or maybe the format
cells for the 'Date' column??
Another question...
What is the code for VB so when information is already entered in the
spreadsheet it will notify me with a dialog box?

Any help will be greatly appreciated as I'm stumped.

Thanks
 
G

Guest

Say input number 290906 is stored in x, then try

Range("A1").Value = DateValue(Left(x, 2) & "/" & Mid(x, 3, 2) & "/" &
Right(x, 2))

Adjust destination cell reference!


As for the other question!
Give more details!

Another question...
What is the code for VB so when information is already entered in the
spreadsheet it will notify me with a dialog box?

Regards,
Stefi
 
G

Guest

Another solution that tolerates differences in international settings:
Range("B1").Value = DateValue(Left(x, 2) &
Application.International(xlDateSeparator) & Mid(x, 3, 2) &
Application.International(xlDateSeparator) & Right(x, 2))

Regards,
Stefi

„Stefi†ezt írta:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top