I have 3 text boxes, accompanied by 3 spinbuttons. spinbuttons put day, month, year into the text boxes. When I enter the values into a cell, it's not in a date format. How do I convert it to a date in vba?
Here's the code I used.
Here's the code I used.
VBA Code:
Private Sub SpinButton1_Change()
If Me.SpinButton1.Value = 0 Then Me.SpinButton1.Value = 31
If Me.SpinButton1.Value = 32 Then Me.SpinButton1.Value = 1
Me.day2.Value = Format(Me.SpinButton1.Value, "00")
End Sub
Private Sub SpinButton2_Change()
If Me.SpinButton2.Value = -1 Then Me.SpinButton2.Value = 12
If Me.SpinButton2.Value = 13 Then Me.SpinButton2.Value = 1
Me.month1.Value = Format(Me.SpinButton2.Value, "00")
End Sub
Private Sub SpinButton3_Change()
If Me.SpinButton3.Value = -1 Then Me.SpinButton3.Value = 2021
If Me.SpinButton3.Value = 2040 Then Me.SpinButton3.Value = 2021
Me.year1.Value = Format(Me.SpinButton3.Value, "00")
End Sub
Private Sub CommandButton2_Click()
Dim x As Long
Dim y As Worksheet
Set y = Sheet2
x = y.Range("A" & Rows.Count).End(xlUp).Row + 1
With y
.Cells(x, 1).Value = Me.day2.Value & ":" & Me.month1.Value & ":" & Me.year1.Value
End With
End Sub