In this with extra option to choose new date
Private Sub CommandButton2_Click()
If Not IsDate(TextBox1) Then
MsgBox "No valid date"
TextBox1 = ""
TextBox1.SetFocus
Exit Sub
Else
Dim mydate As Double
mydate = DateValue(TextBox1)
With Sheets("Attendance")
mycol = Application.Match(mydate, .Range("A8", "XFD8"), 0)
If IsError(mycol) Then
mycol = .Cells(8, .Columns.Count).End(xlToLeft).Offset(, 1).Column
.Cells(8, mycol) = mydate
End If
End With
End If
With Sheets("Attendance")
lr = .Range("A" & Rows.Count).End(xlUp).Row
at = Application.CountA(.Range(.Cells(9, mycol), .Cells(lr, mycol)))
If at > 0 Then
vervolg:
j = InputBox("1 = Cancel" & Chr(13) & "2 = Replace excisting data by new" & Chr(13) & "3 = Choose New Date", "Already data present for this date")
End If
If j = 1 Then
Unload Me
Exit Sub
ElseIf j = 2 Then
For i = 0 To UserForm1.ListBox1.ListCount - 1
myrow = Application.Match(UserForm1.ListBox1.List(i), .Range("A:A"), 0)
If Not IsError(myrow) Then .Cells(myrow, mycol) = "Present"
Next
For i = 0 To UserForm1.ListBox2.ListCount - 1
myrow = Application.Match(UserForm1.ListBox2.List(i), .Range("A:A"), 0)
If Not IsError(myrow) Then .Cells(myrow, mycol) = "Absent"
Next
For i = 0 To UserForm1.ListBox3.ListCount - 1
myrow = Application.Match(UserForm1.ListBox3.List(i), .Range("A:A"), 0)
If Not IsError(myrow) Then .Cells(myrow, mycol) = "Present other"
Next
ElseIf j = 3 Then
TextBox1 = ""
TextBox1.SetFocus
Exit Sub
Else
GoTo vervolg
End If
End With
Unload Me
End Sub
Kind regards
Leo
Bookmarks