KARTINA AZMAN
New Member
Hi.. I need help. I am trying to make an excel file which employee can plan their holiday without overlapping with each others'.
I am now stuck with the "finding date" part. There is a code from ozgrid but I cannot make it work regardless of how I changed the date format.
This is how far I have manage. Kindly help. Thank you.
Username:admin
password: admin
I am now stuck with the "finding date" part. There is a code from ozgrid but I cannot make it work regardless of how I changed the date format.
This is how far I have manage. Kindly help. Thank you.
Code:
Private Sub CommandButton2_Click()
Dim i As Long
Dim strdate As String
Dim rCell As Range
Dim IReply As Long
Dim ws As Worksheet
strdate = Me.tbDtF.Value
'Cancelled
If strdate = "False" Then Exit Sub
strdate = Format(strdate, "Short Date")
On Error Resume Next
For Each ws In ThisWorkbook.Worksheets
If ws.Name = "LIST" Then Exit Sub 'to look for date in calendar sheets only
If ws.Name <> "LIST" Then
Set rCell = Cells.Find(What:=CDate(strdate), After:=Range("A1"), LookIn:=xlFormulas, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False)
End If
If Not rCell Is Nothing Then
'MsgBox "Found at " & rngX.Address
If rCell.Offset(1, 0).Value < 6 Then 'limit for ppl on leave per day is 5
With ThisWorkbook.Worksheets("LIST") 'sending userform entry into worksheet "list"
i = .Cells(.Rows.Count, "A").End(xlUp).Row + 1
.Cells(i, 1).Value = Me.tbUser.Value
.Cells(i, 2).Value = Me.tbDtF.Value
.Cells(i, 3).Value = Me.tbDtT.Value
.Cells(i, 5).Value = Me.tbRemarks.Value
End With
rCell.Offset(1, 0).Value = rCell.Offset(1, 0).Value + 1 'adding value 1 to the cell below found date
rCell.Offset(2, 0).Value = rCell.Offset(2, 0).Value + "," + Me.tbUser.Value 'adding the username to the cell
Else: MsgBox "Sorry, maximum people have applied for leave on that date"
End If
End If
On Error GoTo 0
If rCell Is Nothing Then
lReply = MsgBox("Date cannot be found. Try Again", vbYesNo)
If lReply = vbYes Then UserForm1.tbDtF.SetFocus
If lReply = vbNo Then UserForm1.Hide
End If
Next ws
MsgBox "Your leave booking is submitted"
End Sub
Username:admin
password: admin