Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Userfrom macro that paste onte sheet . Hi, I have made a userform that within th

ID: 3560799 • Letter: U

Question

Userfrom macro that paste onte sheet.

Hi,

I have made a userform that within this userform date's are being inserted from textbox 1 and testbox 2. Then I had made a small macro that when i press Ok from the command button within the userfrom is paste those dates on an excel sheet. The problem is that when those dates enter the excel sheet the date format is not kept.

For example :

Textbox 1: 01/05/2014

Textbox 2 : 02/05/2014

When does dates are inserted onto the excel sheet in cells "L4" and "L5" the postion and also format of the dates sometimes change.

For Example:

"L4" : 05/01/2014

"L5": 05/02/2014

The month value is changeing places with the date value, and also sometimes the dates is not be recognized as an date format.

How could this problem be fixed, the macro is provided here:

Private Sub CommandButton1_Click()
Worksheets("Visa Activity").Activate
Range("L4").Value = Me.TextBox1.Value
Range("L5").Value = Me.TextBox2.Value
Me.hide
Me.TextBox1.Value = " "
Me.TextBox2.Value = " "
End Sub

Thanks

Explanation / Answer

%T6ry it this way. Note I used DD/MM/YYYY so change if necessary for your locale.,/

Private Sub CommandButton1_Click()
Worksheets("Visa Activity").Activate
With Range("L4")
    .NumberFormat = "DD/MM/YYYY"
    .Value = CDate(Me.TextBox1.Value)
End With
With Range("L5")
    .NumberFormat = "DD/MM/YYYY"
    .Value = CDate(Me.TextBox2.Value)
End With
Me.Hide
Me.TextBox1.Value = ""
Me.TextBox2.Value = ""
End Sub

,====

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote