Hello
I've already formatted column 4 with date format as shown below.
Have also explored that if Date is Blank then the value of that cell of 0 date is 30-Dec-1899. Anyways that i can prevent 30-Dec-1899 which are displayed if the cells are blank and cells to remain blank too if no date is entered
So when userform in initialized txtDate.Text displays as 30-Dec-1899. so how can this txtField can remain Blank when UF is initialized
coding ThisWorkbook
userform1
SamD
I've already formatted column 4 with date format as shown below.
Have also explored that if Date is Blank then the value of that cell of 0 date is 30-Dec-1899. Anyways that i can prevent 30-Dec-1899 which are displayed if the cells are blank and cells to remain blank too if no date is entered
So when userform in initialized txtDate.Text displays as 30-Dec-1899. so how can this txtField can remain Blank when UF is initialized
coding ThisWorkbook
Code:
Private Sub Workbook_Open()
Worksheets("Sheet1").Columns(4).NumberFormat = "dd-mmm-yyyy"
End Sub
userform1
Code:
Option Explicit
Dim disableEvents As Boolean
Public dDate As Date
Private Sub txtDate_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
Worksheets("Sheet1").Columns(1).NumberFormat = "dd-mmm-yyyy"
If txtDate.Value = vbNullString Then
Exit Sub
ElseIf Not IsDate(txtDate.Value) Then
Cancel = True
MsgBox "Invalid date, please re-enter", vbCritical
txtDate.Value = vbNullString
txtDate.SetFocus
Worksheets("Sheet1").Range("A2").Value = Format(CDate(txtDate.Value), "dd-mmm-yyyy")
Exit Sub
End If
dDate = DateSerial(Year(Date), Month(Date), Day(Date))
txtDate.Value = Format(CDate(txtDate.Value), "dd-mmm-yyyy")
Worksheets("Sheet1").Range("A2").Value = Format(CDate(txtDate.Value), "dd-mmm-yyyy")
End Sub
Private Sub UserForm_Initialize()
Load UserForm1
UserForm1.Show vbModeless
txtDate.Value = Format(CDate(Worksheets("Sheet1").Range("A2").Value), "dd-mmm-yyyy")
End Sub
Last edited: