I have prepared a small vba user form for entering the leave details. While entering the date in "From" and "To" fields (text boxes)in teh format dd/mm/yyyy, the data is written in the excel sheet as mm/dd/yyyy. Please help to rectify the error.
I am appending the script...
Private Sub cmdClose1_Click()
Unload Me
End Sub
Private Sub cmdOK1_Click()
Dim RowCount As Long
Dim ctl As Control
If Not IsNumeric(Me.txtEmp.Value) Then
MsgBox "The Employee Number is Wrong.", vbExclamation, "Error"
Me.txtEmp.SetFocus
Exit Sub
End If
If Not IsDate(Me.txtFrom.Value) Then
MsgBox "Please Enter the From Date Correctly.", vbExclamation, "Error"
Me.txtFrom.SetFocus
Exit Sub
End If
If Not IsDate(Me.txtTo.Value) Then
MsgBox "Please Enter the To Date Correctly.", vbExclamation, "Error"
Me.txtTo.SetFocus
Exit Sub
End If
If Me.txtDays.Value = "" Then
MsgBox "Please Enter No of Days.", vbExclamation, "Error"
Me.txtDays.SetFocus
Exit Sub
End If
RowCount = Worksheets("Data").Range("A1").CurrentRegion.Rows.Count
With Worksheets("Data").Range("A1")
.Offset(RowCount, 0).Value = Me.txtEmp.Value
.Offset(RowCount, 1).Value = Me.txtFrom.Value
.Offset(RowCount, 2).Value = Me.txtTo.Value
.Offset(RowCount, 3).Value = Me.txtDays.Value
.Offset(RowCount, 4).Value = Me.cboType.Value
End With
For Each ctl In Me.Controls
txtEmp.Text = ""
txtFrom.Text = ""
txtTo.Text = ""
txtDays.Text = ""
Next ctl
End Sub
Bookmarks