Try pasting this into the UserForm code window. Untested here.
The name references to the various controls may need to be edited to work on your end.
Private Sub CommandButton2_Click()
TextBox1 = Format(Date, "dd/mm/yyyy")
End Sub
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
On Error Resume Next
Dim enteredDate As Date
enteredDate = DateValue(TextBox1.Text)
If Err.Number = 0 Then
TextBox1.Text = Format(enteredDate, "dd/mm/yyyy")
Else
MsgBox "Please enter a valid date in dd/mm/yyyy format.", vbExclamation
TextBox1.SetFocus
Cancel = True
End If
On Error GoTo 0
End Sub
Private Sub CommandButton1_Click()
ActiveSheet.Select
Dim LastRow As Object
Dim formattedDate As String
Set LastRow = ActiveSheet.Range("A65536").End(xlUp)
formattedDate = Format(DateValue(TextBox1.Text), "dd/mm/yyyy")
LastRow.Offset(1, 0).Value = formattedDate
LastRow.Offset(1, 1).Value = TextBox2.Text
LastRow.Offset(1, 2).Value = TextBox3.Text
LastRow.Offset(1, 3).Value = TextBox4.Text
LastRow.Offset(1, 4).Value = ComboBox2.Value
LastRow.Offset(1, 5).Value = ComboBox1.Text
MsgBox "Transaction added"
Dim response As VbMsgBoxResult
response = MsgBox("Do you want to add another transaction?", vbYesNo)
If response = vbYes Then
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
ComboBox2.Text = ""
ComboBox1.Text = ""
TextBox1.SetFocus
Else
Unload Me
End If
End Sub
Bookmarks