bloodmilksky
Board Regular
- Joined
- Feb 3, 2016
- Messages
- 202
hi Guys,
I am currently using the below code for a holiday request form it takes the values on sheet 1:
Employee Name : B7
Employee Number : B9
Team : B11
matches them against a reference on their team holiday sheet (determined on sheet1 B11) To Book Holiday in on dates determined in :
Sheet 1 From(b21) To(C21) Half Or Full Day (D21)
What I am having trouble with is the booking of the holidays as at most I can only have 2 people off at a time but it is letting more than that and is also letting them exceed their allotted holiday which is determined in the request form (25days Sheet 1 B12)
would anyone know to put in a statement so if there is already 2 people off it would reply with a error message and the same for if they exceeded their holiday limit ( Sheet1 B12)
any questions I am more than happy to answer
many thanks
jamie
I am currently using the below code for a holiday request form it takes the values on sheet 1:
Employee Name : B7
Employee Number : B9
Team : B11
matches them against a reference on their team holiday sheet (determined on sheet1 B11) To Book Holiday in on dates determined in :
Sheet 1 From(b21) To(C21) Half Or Full Day (D21)
What I am having trouble with is the booking of the holidays as at most I can only have 2 people off at a time but it is letting more than that and is also letting them exceed their allotted holiday which is determined in the request form (25days Sheet 1 B12)
would anyone know to put in a statement so if there is already 2 people off it would reply with a error message and the same for if they exceeded their holiday limit ( Sheet1 B12)
any questions I am more than happy to answer
many thanks
jamie
Code:
[B]Sub NewBookingCheck()[/B]
[B]Dim Name As String, Team As String, StartRng As String, EndRng As String, ShiftRng As String, Final As String[/B]
[B]Dim LastRow As Long[/B]
[B]Dim Rng As Range, Rng2 As Range, cRange As Range, Cell As Range[/B]
[B]Team = Sheets(“Sheet1”).Range("B11").Value[/B]
[B]Name = Team & Replace(Sheets(“Sheet1”).Range("B7").Value, " ", "")[/B]
[B]LastRow = Sheets(Team).Cells(Rows.Count, "A").End(xlUp).Row[/B]
[B]If Sheets(“Sheet1”).Range("B21").Value = Sheets(“Sheet1”).Range("C21").Value Then[/B]
[B] StartRng = Left(Sheets(“Sheet1”).Range("B21").Value, 2) & Mid(Sheets(“Sheet1”).Range("B21").Value, 4, 2) & Right(Sheets(“Sheet1”).Range("B21").Value, 2)[/B]
[B] If Sheets(“Sheet1”).Range("D21").Value <> "" Then[/B]
[B] ShiftRng = Sheets(“Sheet1”).Range("D21").Value[/B]
[B] Else[/B]
[B] ShiftRng = "Full"[/B]
[B] End If[/B]
[B] Final = Team & StartRng & ShiftRng[/B]
[B] Set Rng = Intersect(Sheets(Team).Range(Name), Sheets(Team).Range(Final))[/B]
[B] If Application.WorksheetFunction.CountA(Sheets(Team).Range(Sheets(Team).Cells(3, Rng.Column), Sheets(Team).Cells(LastRow, Rng.Column))) < 2 Then[/B]
[B] Rng.Interior.ColorIndex = 6[/B]
[B] Rng.Value = "BOOKED"[/B]
[B] Rng.Font.Bold = True[/B]
[B] End If[/B]
[B]Else[/B]
[B] StartRng = Left(Sheets(“Sheet1”).Range("B21").Value, 2) & Mid(Sheets(“Sheet1”).Range("B21").Value, 4, 2) & Right(Sheets(“Sheet1”).Range("B21").Value, 2)[/B]
[B] EndRng = Left(Sheets(“Sheet1”).Range("C21").Value, 2) & Mid(Sheets(“Sheet1”).Range("C21").Value, 4, 2) & Right(Sheets(“Sheet1”).Range("C21").Value, 2)[/B]
[B] ShiftRng = "Full"[/B]
[B] Final = Team & StartRng & ShiftRng[/B]
[B] Set Rng = Intersect(Sheets(Team).Range(Name), Sheets(Team).Range(Final))[/B]
[B] Final = Team & EndRng & ShiftRng[/B]
[B] Set Rng2 = Intersect(Sheets(Team).Range(Name), Sheets(Team).Range(Final))[/B]
[B] Set cRange = Sheets(Team).Range(Rng, Rng2)[/B]
[B] For Each Cell In cRange[/B]
[B] If Application.WorksheetFunction.CountA(Sheets(Team).Range(Sheets(Team).Cells(3, Cell.Column), Sheets(Team).Cells(LastRow, Cell.Column))) < 2 Then[/B]
[B] Cell.Interior.ColorIndex = 6[/B]
[B] Cell.Value = "BOOKED"[/B]
[B] Cell.Font.Bold = True[/B]
[B] End If[/B]
[B] Next Cell[/B]
[B]End If[/B]
[B]MsgBox "Complete"[/B]
[B]Run "HaveYouFinished"[/B]
[B]End Sub[/B]