...

MS Excel VBA

To Do List With Excel VBA User form

To Do List With Excel VBA User form

  MS Excel VBA created a calendar using the class on the user form, and there are an hour and related text boxes on the user form. The desired date selected from the calendar and the notes added for the date are entered in the text boxes and then saved in the relevant cells on the worksheet. The calendar obscures the years from 2020 to 2025 and is created according to the user’s system terminology. Column A of the Sheet lists dates between 2020 and 2025 by day, month, and year. The hour is recorded on the headers from column (C) to column (P).
  Private WithEvents Calendar1 As cCalendar
Dim i As Byte, cor, cor2, cor3 As String
Private Sub Calendar1_Click()
On Error Resume Next
Dim RNG As Range
Set RNG = Sheets("Calendar").Range("A2:A" & Range("A" & Rows.Count).End(xlUp).Row).Find(CDate(Calendar1.Value), , xlValues, xlWhole)

If Not RNG Is Nothing Then
Sheets("Calendar").Cells(RNG.Row, 1).Select
TextBox5.Text = Sheets("Calendar").Cells(RNG.Row, 2).Value
For i = 6 To 19
Controls("TextBox" & i).Text = Sheets("Calendar").Cells(RNG.Row, i - 3).Value
Next
Else
MsgBox "The selected date not available.", vbCritical, " "
End If
End Sub

Private Sub CommandButton1_Click()
Dim RNG As Range, y As Byte
Set RNG = Sheets("Calendar").Range("A1:A" & Range("A" & Rows.Count).End(xlUp).Row).Find(CDate(Calendar1.Value), , xlValues, xlWhole)
If Not RNG Is Nothing Then
Sheets("Calendar").Cells(RNG.Row, 2).Value = TextBox5.Text
For i = 6 To 18
Sheets("Calendar").Cells(RNG.Row, i - 3).Value = Controls("TextBox" & i).Text
Next
End If
cor2 = MsgBox("The Calendar were saved", vbInformation, " ")

For y = 2 To 16
Sheets("Calendar").Columns(y).EntireColumn.WrapText = True
Next
End Sub
Private Sub CommandButton10_Click()
cor = MsgBox("Do you want to delete Calendar?", vbYesNo, " ")
If cor = vbNo Then Exit Sub
TextBox12.Value = ""
gir
End Sub
Private Sub CommandButton11_Click()
cor = MsgBox("Do you want to delete Calendar?", vbYesNo, " ")
If cor = vbNo Then Exit Sub
TextBox13.Value = ""
gir
End Sub

Private Sub CommandButton12_Click()
cor = MsgBox("Do you want to delete Calendar?", vbYesNo, " ")
If cor = vbNo Then Exit Sub
TextBox14.Value = ""
gir
End Sub

Private Sub CommandButton13_Click()
cor = MsgBox("Do you want to delete Calendar?", vbYesNo, " ")
If cor = vbNo Then Exit Sub
TextBox15.Value = ""
gir
End Sub

Private Sub CommandButton14_Click()
cor = MsgBox("Do you want to delete Calendar?", vbYesNo, " ")
If cor = vbNo Then Exit Sub
TextBox16.Value = ""
gir
End Sub

Private Sub CommandButton15_Click()
cor = MsgBox("Do you want to delete Calendar?", vbYesNo, " ")
If cor = vbNo Then Exit Sub

TextBox17.Value = ""
gir
End Sub

Private Sub CommandButton16_Click()
cor = MsgBox("Do you want to delete Calendar?", vbYesNo, " ")
If cor = vbNo Then Exit Sub
TextBox18.Value = ""
gir
End Sub

Private Sub CommandButton17_Click()
cor = MsgBox("Do you want to delete Calendar?", vbYesNo, " ")
If cor = vbNo Then Exit Sub
TextBox5.Value = ""
gir
End Sub

Private Sub CommandButton18_Click()
cor3 = MsgBox("Do you want to save the workbook?", vbYesNo, " ")
If cor3 = vbNo Then
   ActiveWorkbook.Close SaveChanges:=False
   Else
   ActiveWorkbook.Save
   Application.Quit
   End If

End Sub

Private Sub CommandButton3_Click()
Dim RNG As Range
Set RNG = Sheets("Calendar").Range("A1:A" & Range("A" & Rows.Count).End(xlUp).Row).Find(CDate(Calendar1.Value), , xlValues, xlWhole)
If Not RNG Is Nothing Then
Sheets("Calendar").Cells(RNG.Row, 2).Value = TextBox5.Text
For i = 6 To 18
Sheets("Calendar").Cells(RNG.Row, i - 3).Value = Controls("TextBox" & i).Text
Next
End If
cor2 = MsgBox("The Calendar were changed", vbInformation, " ")
End Sub

Private Sub CommandButton4_Click()
cor = MsgBox("Do you want to delete Calendar?", vbYesNo, " ")
If cor = vbNo Then Exit Sub
TextBox6.Value = ""
gir
End Sub

Private Sub Image1_Click()
TextBox6.Value = ""
CommandButton1.SetFocus
End Sub

Private Sub CommandButton5_Click()
cor = MsgBox("Do you want to delete Calendar?", vbYesNo, " ")
If cor = vbNo Then Exit Sub
TextBox7.Value = ""
gir
End Sub

Private Sub CommandButton6_Click()
cor = MsgBox("Do you want to delete Calendar?", vbYesNo, " ")
If cor = vbNo Then Exit Sub
TextBox8.Value = ""
gir
End Sub

Private Sub CommandButton7_Click()
cor = MsgBox("Do you want to delete Calendar?", vbYesNo, " ")
If cor = vbNo Then Exit Sub
TextBox9.Value = ""
gir
End Sub

Private Sub CommandButton8_Click()
cor = MsgBox("Do you want to delete Calendar?", vbYesNo, " ")
If cor = vbNo Then Exit Sub
TextBox10.Value = ""
gir
End Sub

Private Sub CommandButton9_Click()
cor = MsgBox("Do you want to delete Calendar?", vbYesNo, " ")
If cor = vbNo Then Exit Sub
TextBox11.Value = ""
gir
End Sub



Private Sub gir()
Dim RNG As Range
Set RNG = Sheets("Calendar").Range("A1:A" & Range("A" & Rows.Count).End(xlUp).Row).Find(CDate(Calendar1.Value), , xlValues, xlWhole)
If Not RNG Is Nothing Then
Sheets("Calendar").Cells(RNG.Row, 2).Value = TextBox5.Text
For i = 6 To 18
Sheets("Calendar").Cells(RNG.Row, i - 3).Value = Controls("TextBox" & i).Text
Next
End If
End Sub


Private Sub UserForm_Initialize()
 Set Calendar1 = New cCalendar
    Calendar1.Add_Calendar_into_Frame Me.Frame1
TextBox6.EnterKeyBehavior = True
For i = 5 To 18
Controls("TextBox" & i).EnterKeyBehavior = True
Controls("TextBox" & i).ScrollBars = fmScrollBarsBoth
Next
Calendar1_Click

End Sub
  

Code Explanation:

  Private WithEvents Calendar1 As cCalendar
Dim i As Byte, cor, cor2, cor3 As String  
Declare the globe variables.
  Private Sub CommandButton1_Click()
Dim RNG As Range, y As Byte
Set RNG = Sheets("Calendar").Range("A1:A" & Range("A" & Rows.Count).End(xlUp).Row).Find(CDate(Calendar1.Value), , xlValues, xlWhole)
If Not RNG Is Nothing Then
Sheets("Calendar").Cells(RNG.Row, 2).Value = TextBox5.Text
For i = 6 To 18
Sheets("Calendar").Cells(RNG.Row, i - 3).Value = Controls("TextBox" & i).Text
Next
End If
cor2 = MsgBox("The Calendar were saved", vbInformation, " ")

For y = 2 To 16
Sheets("Calendar").Columns(y).EntireColumn.WrapText = True
Next
End Sub
  
Save Button
  Private Sub CommandButton10_Click()
cor = MsgBox("Do you want to delete Calendar?", vbYesNo, " ")
If cor = vbNo Then Exit Sub
TextBox12.Value = ""
gir
End Sub
Private Sub CommandButton11_Click()
cor = MsgBox("Do you want to delete Calendar?", vbYesNo, " ")
If cor = vbNo Then Exit Sub
TextBox13.Value = ""
gir
End Sub

Private Sub CommandButton12_Click()
cor = MsgBox("Do you want to delete Calendar?", vbYesNo, " ")
If cor = vbNo Then Exit Sub
TextBox14.Value = ""
gir
End Sub

Private Sub CommandButton13_Click()
cor = MsgBox("Do you want to delete Calendar?", vbYesNo, " ")
If cor = vbNo Then Exit Sub
TextBox15.Value = ""
gir
End Sub

Private Sub CommandButton14_Click()
cor = MsgBox("Do you want to delete Calendar?", vbYesNo, " ")
If cor = vbNo Then Exit Sub
TextBox16.Value = ""
gir
End Sub

Private Sub CommandButton15_Click()
cor = MsgBox("Do you want to delete Calendar?", vbYesNo, " ")
If cor = vbNo Then Exit Sub

TextBox17.Value = ""
gir
End Sub

Private Sub CommandButton16_Click()
cor = MsgBox("Do you want to delete Calendar?", vbYesNo, " ")
If cor = vbNo Then Exit Sub
TextBox18.Value = ""
gir
End Sub

Private Sub CommandButton17_Click()
cor = MsgBox("Do you want to delete Calendar?", vbYesNo, " ")
If cor = vbNo Then Exit Sub
TextBox5.Value = ""
gir
End Sub
  
Delete Icon Button
  Private Sub CommandButton3_Click()
Dim RNG As Range
Set RNG = Sheets("Calendar").Range("A1:A" & Range("A" & Rows.Count).End(xlUp).Row).Find(CDate(Calendar1.Value), , xlValues, xlWhole)
If Not RNG Is Nothing Then
Sheets("Calendar").Cells(RNG.Row, 2).Value = TextBox5.Text
For i = 6 To 18
Sheets("Calendar").Cells(RNG.Row, i - 3).Value = Controls("TextBox" & i).Text
Next
End If
cor2 = MsgBox("The Calendar were changed", vbInformation, " ")
End Sub  
Change Button
  Private Sub gir()
Dim RNG As Range
Set RNG = Sheets("Calendar").Range("A1:A" & Range("A" & Rows.Count).End(xlUp).Row).Find(CDate(Calendar1.Value), , xlValues, xlWhole)
If Not RNG Is Nothing Then
Sheets("Calendar").Cells(RNG.Row, 2).Value = TextBox5.Text
For i = 6 To 18
Sheets("Calendar").Cells(RNG.Row, i - 3).Value = Controls("TextBox" & i).Text
Next
End If
End Sub  
Find The Last row Fill dates
  Private Sub UserForm_Initialize()
 Set Calendar1 = New cCalendar
    Calendar1.Add_Calendar_into_Frame Me.Frame1
TextBox6.EnterKeyBehavior = True
For i = 5 To 18
Controls("TextBox" & i).EnterKeyBehavior = True
Controls("TextBox" & i).ScrollBars = fmScrollBarsBoth
Next
Calendar1_Click

End Sub
  
User Form Initialize create a calander

Leave a Comment

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


Scroll to Top