PDA

View Full Version : User Form Date



clairedon
10-12-2006, 03:30 AM
Please Help!
I have Excel spreadsheets, and a VBA form that takes input from the user and adds it to the Excel form. My problem i'm sure is a simple one, but its bugging me. I enter the date format in the text box as dd/mm/yyyy, and want it to print in the spreadsheet as same, however it prints as mm/dd/yyyy. Does anybody know what i'm doing wrong?
Thanks in advance

Bob Phillips
10-12-2006, 03:48 AM
Range("A1").Value = CDate(TextBox1.Text)

matthewspatrick
10-12-2006, 07:45 AM
clairedon,

I never trust VBA to do the right thing with m/d/yyyy or d/m/yyyy date formats. I recommend using unambiguous formats like d mmm yyyy, or doing things like using the Calendar or DateTimePicker controls, or using separate controls for month, day, and year.

Charlize
10-13-2006, 02:40 AM
use a variable defined as date. put variable in cell.

Option Explicit
Sub test_format()
Dim dt As Date
dt = InputBox("Give date - xx/mm/yyyy", "Please give date ...")
With Sheets(1)
.Cells(ActiveCell.Row, ActiveCell.Column).Value = FormatDateTime(dt, 1)
End With
End Sub

Charlize