Option Explicit
Dim d As Object, e As Object
Dim va As Variant
Private Sub btnCancel_Click()
Unload Me
End Sub
Private Sub btnClear_Click()
End Sub
Private Sub ComboBox1_Enter()
Call toPopulate(1)
End Sub
Private Sub ComboBox10_Enter()
Call toPopulate(10)
End Sub
Private Sub ComboBox11_Enter()
Call toPopulate(11)
End Sub
Private Sub ComboBox12_Enter()
Call toPopulate(12)
End Sub
Private Sub ComboBox13_Enter()
Call toPopulate(13)
End Sub
Private Sub ComboBox14_Enter()
Call toPopulate(14)
End Sub
Private Sub ComboBox15_Enter()
Call toPopulate(15)
End Sub
Private Sub ComboBox16_Enter()
Call toPopulate(16)
End Sub
Private Sub ComboBox17_Enter()
Call toPopulate(17)
End Sub
Private Sub ComboBox18_Enter()
Call toPopulate(18)
End Sub
Private Sub ComboBox19_Enter()
Call toPopulate(19)
End Sub
Private Sub ComboBox2_Enter()
Call toPopulate(2)
End Sub
Private Sub ComboBox20_Enter()
Call toPopulate(20)
End Sub
Private Sub ComboBox21_Enter()
Call toPopulate(21)
End Sub
Private Sub ComboBox22_Enter()
Call toPopulate(22)
End Sub
Private Sub ComboBox23_Enter()
Call toPopulate(23)
End Sub
Private Sub ComboBox24_Enter()
Call toPopulate(24)
End Sub
Private Sub ComboBox25_Enter()
Call toPopulate(25)
End Sub
Private Sub ComboBox26_Enter()
Call toPopulate(26)
End Sub
Private Sub ComboBox27_Enter()
Call toPopulate(27)
End Sub
Private Sub ComboBox28_Enter()
Call toPopulate(28)
End Sub
Private Sub ComboBox29_Enter()
Call toPopulate(29)
End Sub
Private Sub ComboBox3_Enter()
Call toPopulate(3)
End Sub
Private Sub ComboBox30_Enter()
Call toPopulate(30)
End Sub
Private Sub ComboBox31_Enter()
Call toPopulate(31)
End Sub
Private Sub ComboBox32_Enter()
Call toPopulate(32)
End Sub
Private Sub ComboBox4_Enter()
Call toPopulate(4)
End Sub
Private Sub ComboBox5_Enter()
Call toPopulate(5)
End Sub
Private Sub ComboBox6_Enter()
Call toPopulate(6)
End Sub
Private Sub ComboBox7_Enter()
Call toPopulate(7)
End Sub
Private Sub ComboBox8_Enter()
Call toPopulate(8)
End Sub
Private Sub ComboBox9_Enter()
Call toPopulate(9)
End Sub
Private Sub TextBox1_AfterUpdate()
Dim tString As String
With TextBox1
'Check if user put in a colon or not
If InStr(1, .Value, ":", vbTextCompare) = 0 Then
'If not, make string 4 digits and insert colon
tString = Format(.Value, "0000")
tString = Left(tString, 2) & ":" & Right(tString, 2)
TextBox1.Value = Format(TimeValue(tString), "HH:MM AM/PM")
Else
'Otherwise, take value as given
.Value = Format(.Value, "hh:mm AM/PM")
End If
End With
End Sub
Private Sub TextBox2_AfterUpdate()
Dim tString As String
With TextBox2
'Check if user put in a colon or not
If InStr(1, .Value, ":", vbTextCompare) = 0 Then
'If not, make string 4 digits and insert colon
tString = Format(.Value, "0000")
tString = Left(tString, 2) & ":" & Right(tString, 2)
TextBox2.Value = Format(TimeValue(tString), "HH:MM AM/PM")
Else
'Otherwise, take value as given
.Value = Format(.Value, "hh:mm AM/PM")
End If
End With
End Sub
Private Sub TextBox3_AfterUpdate()
Dim tString As String
With TextBox3
'Check if user put in a colon or not
If InStr(1, .Value, ":", vbTextCompare) = 0 Then
'If not, make string 4 digits and insert colon
tString = Format(.Value, "0000")
tString = Left(tString, 2) & ":" & Right(tString, 2)
TextBox3.Value = Format(TimeValue(tString), "HH:MM AM/PM")
Else
'Otherwise, take value as given
.Value = Format(.Value, "hh:mm AM/PM")
End If
End With
End Sub
Private Sub TextBox4_AfterUpdate()
Dim tString As String
With TextBox4
'Check if user put in a colon or not
If InStr(1, .Value, ":", vbTextCompare) = 0 Then
'If not, make string 4 digits and insert colon
tString = Format(.Value, "0000")
tString = Left(tString, 2) & ":" & Right(tString, 2)
TextBox4.Value = Format(TimeValue(tString), "HH:MM AM/PM")
Else
'Otherwise, take value as given
.Value = Format(.Value, "hh:mm AM/PM")
End If
End With
End Sub
Private Sub txtbxDate_AfterUpdate()
Dim todaysDate As String
todaysDate = Format(Me.txtbxDate.Value, "long date")
If IsDate(Me.txtbxDate.Text) Then
Me.txtbxDate.Text = todaysDate
End If
End Sub
Private Sub txtbxDate_Enter()
Me.txtbxDate.Value = ""
End Sub
Private Sub UserForm_Initialize()
' Dim ctrl As Control
'
' For Each ctrl In UserForm1.Controls
' If TypeName(ctrl) = "TextBox" Then ctrl.Value = ""
' If TypeName(ctrl) = "ComboBox" Then
' ctrl.List = Sheets("Employees").Range("A2:A" & Range("A" & Rows.Count).End(xlUp).Row).Value
' End If
' Next
Set d = CreateObject("scripting.dictionary"): d.CompareMode = vbTextCompare
Set e = CreateObject("scripting.dictionary"): e.CompareMode = vbTextCompare
With Sheets("Employees")
va = .Range("A2", .Cells(.Rows.Count, "A").End(xlUp))
End With
End Sub
Private Sub toPopulate(n As Long)
Dim i As Long
Dim tx As String
Dim x
d.RemoveAll
e.RemoveAll
For i = 1 To 6
tx = Me.Controls("Combobox" & i).Value
If tx <> "" And i <> n Then e(tx) = Empty
Next
If e.Count <> 0 Then
For Each x In va
If Not e.Exists(x) Then d(x) = Empty
Next
Else
For Each x In va
d(x) = Empty
Next
End If
Me.Controls("Combobox" & n).List = d.keys
End Sub