User Form Clock More Controls in Excel

Benny writes: I want to complete a simple VBA project as I am interested in learning this coding language.
My project is as follows 1. I want to have a combox that contains 5 items e.g \”A\” \”B\” \”C\” \”D\” \”E\”
2. I want to have a real time clock displaying time
3. I want a box that a person can input a time
4. when the inputted time is less than or equal to the realtime an indication says \”on time\”
5 when the inputted time is more than or equal to the realtime an indication says \”late\”
6. And finally if possible I would like a tickbox that will grey out all the other controls when ticked. When unticked the user can input the time

The complete code along with the VBA training video is given below:
Private Sub CheckBox1_Click()
If CheckBox1.Value = True Then
TextBox2.BackColor = &H8000000F
TextBox3.BackColor = &H8000000F
ListBox1.BackColor = &H8000000F
CommandButton1.BackColor = &H80000012
CommandButton2.BackColor = &H80000012
CommandButton3.BackColor = &H80000012
TextBox4.BackColor = &H80000012
End If
If CheckBox1.Value = False Then
TextBox2.BackColor = &H8000000F
TextBox3.BackColor = &H80000005
ListBox1.BackColor = &H80000005
CommandButton1.BackColor = &H8000000F
CommandButton2.BackColor = &H8000000F
CommandButton3.BackColor = &H8000000F
TextBox4.BackColor = &H80000005
End If
End Sub

Private Sub CommandButton1_Click()
Range(“A2”) = ListBox1.Value
If TimeValue(TextBox2) > TimeValue(Now) Then
TextBox3.Text = “Late”
Range(“C2”) = TextBox3.Text
Range(“B2”) = TimeValue(TextBox2.Text)
Else TextBox3.Text = “On Time”
Range(“C2”) = TextBox3.Text
Range(“B2”) = TimeValue(TextBox2.Text)
End If
End Sub

Private Sub CommandButton2_Click()
TextBox2.Text = “”
TextBox3.Text = “”
ListBox1.SetFocus
Range(“A2”) = “”
Range(“B2”) = “” Range(“C2”) = “”
End Sub
Private Sub CommandButton3_Click()
End
End Sub

Private Sub UserForm_Activate()
ListBox1.List = Array(“A”, “B”, “C”, “D”, “E”)
ListBox1.SetFocus
Dim CM As Boolean
Do
If CM = True Then Exit Sub
TextBox4 = Format(Now, “hh:mm:ss”)
DoEvents
Loop
End Sub

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
CM = True
End Sub


Watch the video on youtube

Leave a Reply

Your email address will not be published. Required fields are marked *