Hi all folks,
I have a problem with the date format in a userform:
I've designed this simple UF to manage the annual expense about to car costs. The UF works well, you insert the type of cost, the ammount and the date of the cost.
Nut when I press the OK button to insert the data in the worksheet the date formate insede the third column isn't correct, because excel read the date in US way (I mean, the month before the day) and not in the EU way, even if I've assigned the correct numberformat to the third column that is
NumberFormat = "dd/mm/yyyy"
I realy can't understand why...maybe it's because of the spinbutton that I use to increse or decrease the days that containt the method CDate???
I attach a stamp of the running userform...I know it's in Italian but I think it's easy to undestand...let me know.
Thank you guys..
Here is the code:
Private Sub SpinButton1_Change()
Sub SpinButton1_SpinDown()
Me.TxtDate = CDate(Me.TxtDate) - Me.SpinButton1.SmallChange
End Sub
Sub SpinButton1_SpinUp()
Me.TxtDate = CDate(Me.TxtDate) + Me.SpinButton1.SmallChange
End Sub
With SpinButton1
.SmallChange = 1
.Min = 1
.Max = 100
End With
End Sub
Private Sub UserForm_Initialize()
Dim VoceSpesa As Variant
VoceSpesa = Array("carburante", "autostrada", "altro")
For i = 0 To UBound(VoceSpesa)
With Me.CboVoce
.AddItem VoceSpesa(i)
End With
Next i
Me.TxtDate.Value = Format(Date, "medium date")
End Sub
Private Sub CmdInserisci_Click()
Dim lRow As Long
Set ws = Worksheets("Spese")
'find first empty row in database
lRow = ws.Cells(Rows.Count, 1) _
.End(xlUp).Offset(1, 0).Row
With ws
.Cells(lRow, 1).Value = Me.CboVoce.Value
If CheckBox1 = True Then Cells(lRow, 1).Font.ColorIndex = 4
If CheckBox2 = True Then Cells(lRow, 1).Font.ColorIndex = 3
If CheckBox3 = True Then Cells(lRow, 1).Font.ColorIndex = 5
.Cells(lRow, 2).Value = Me.TxtCommento.Value
.Cells(lRow, 3).Value = Me.TxtDate.Value
.Cells(lRow, 3).NumberFormat = "dd/mm/yyyy"
.Cells(lRow, 4).NumberFormat = "$ #.##0"
.Cells(lRow, 4).Value = Me.TxtValue.Value
End With
End Sub
I have a problem with the date format in a userform:
I've designed this simple UF to manage the annual expense about to car costs. The UF works well, you insert the type of cost, the ammount and the date of the cost.
Nut when I press the OK button to insert the data in the worksheet the date formate insede the third column isn't correct, because excel read the date in US way (I mean, the month before the day) and not in the EU way, even if I've assigned the correct numberformat to the third column that is
NumberFormat = "dd/mm/yyyy"
I realy can't understand why...maybe it's because of the spinbutton that I use to increse or decrease the days that containt the method CDate???
I attach a stamp of the running userform...I know it's in Italian but I think it's easy to undestand...let me know.
Thank you guys..
Here is the code:
Private Sub SpinButton1_Change()
Sub SpinButton1_SpinDown()
Me.TxtDate = CDate(Me.TxtDate) - Me.SpinButton1.SmallChange
End Sub
Sub SpinButton1_SpinUp()
Me.TxtDate = CDate(Me.TxtDate) + Me.SpinButton1.SmallChange
End Sub
With SpinButton1
.SmallChange = 1
.Min = 1
.Max = 100
End With
End Sub
Private Sub UserForm_Initialize()
Dim VoceSpesa As Variant
VoceSpesa = Array("carburante", "autostrada", "altro")
For i = 0 To UBound(VoceSpesa)
With Me.CboVoce
.AddItem VoceSpesa(i)
End With
Next i
Me.TxtDate.Value = Format(Date, "medium date")
End Sub
Private Sub CmdInserisci_Click()
Dim lRow As Long
Set ws = Worksheets("Spese")
'find first empty row in database
lRow = ws.Cells(Rows.Count, 1) _
.End(xlUp).Offset(1, 0).Row
With ws
.Cells(lRow, 1).Value = Me.CboVoce.Value
If CheckBox1 = True Then Cells(lRow, 1).Font.ColorIndex = 4
If CheckBox2 = True Then Cells(lRow, 1).Font.ColorIndex = 3
If CheckBox3 = True Then Cells(lRow, 1).Font.ColorIndex = 5
.Cells(lRow, 2).Value = Me.TxtCommento.Value
.Cells(lRow, 3).Value = Me.TxtDate.Value
.Cells(lRow, 3).NumberFormat = "dd/mm/yyyy"
.Cells(lRow, 4).NumberFormat = "$ #.##0"
.Cells(lRow, 4).Value = Me.TxtValue.Value
End With
End Sub