Eric Carolus
Board Regular
- Joined
- Sep 17, 2012
- Messages
- 133
- Office Version
- 2016
- Platform
- Windows
Hi folks.
I am setting up an invigilation roster in which an educator can only be assigned once per day per room. If you attempt to assign the educator again for the same day, then Excel needs warns you and delete your second assignment of the educator. I can do this for one day, and it works for one day, but I I struggle have this done for, say, 10 days (with different dates). In other words in Range(“C5:R5”) if there is an attempt to place any teacher more than once, then Excel must warn me.
I have managed this with the code below. I wish to do the same for the ranges (C6:R6, C7:R7, C8:R8), etc.
The abbreviations on the right are the codes referring to teachers. The numbers on the RIGHT simply refers to the total of times the teacher had been assigned on the whole grid.
My code for the topmost row (C5:R5), as follows:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim iVal As Integer 'Correcct
Dim myRange As Range 'Correct
Set myRange = Application.ActiveWorkbook.Sheets("CountPeriods").Range("C5:R5")
iVal = Application.WorksheetFunction.CountIf(myRange, "AC") Or Application.WorksheetFunction.CountIf(myRange, "ZAM") Or Application.WorksheetFunction.CountIf(myRange, "ZS") _
Or Application.WorksheetFunction.CountIf(myRange, "SF") Or Application.WorksheetFunction.CountIf(myRange, "LJ") Or Application.WorksheetFunction.CountIf(myRange, "NL") _
Or Application.WorksheetFunction.CountIf(myRange, "LM") Or Application.WorksheetFunction.CountIf(myRange, "AMJ") Or Application.WorksheetFunction.CountIf(myRange, "AMV") _
Or Application.WorksheetFunction.CountIf(myRange, "VN") Or Application.WorksheetFunction.CountIf(myRange, "MN") Or Application.WorksheetFunction.CountIf(myRange, "NQ") _
Or Application.WorksheetFunction.CountIf(myRange, "SR") Or Application.WorksheetFunction.CountIf(myRange, "GS") Or Application.WorksheetFunction.CountIf(myRange, "DS") _
Or Application.WorksheetFunction.CountIf(myRange, "CS") Or Application.WorksheetFunction.CountIf(myRange, "PS") Or Application.WorksheetFunction.CountIf(myRange, "JT") _
Or Application.WorksheetFunction.CountIf(myRange, "MY")
If iVal > 1 Then
On Error Resume Next
MsgBox "This teacher had ALREADY been entered once!"
Selection.Offset(0, -1).ClearContents
Selection.Offset(0, -1).Select
Exit Sub
End If
End Sub
Please help.
Thanks in advance.
I am setting up an invigilation roster in which an educator can only be assigned once per day per room. If you attempt to assign the educator again for the same day, then Excel needs warns you and delete your second assignment of the educator. I can do this for one day, and it works for one day, but I I struggle have this done for, say, 10 days (with different dates). In other words in Range(“C5:R5”) if there is an attempt to place any teacher more than once, then Excel must warn me.
I have managed this with the code below. I wish to do the same for the ranges (C6:R6, C7:R7, C8:R8), etc.
The abbreviations on the right are the codes referring to teachers. The numbers on the RIGHT simply refers to the total of times the teacher had been assigned on the whole grid.
My code for the topmost row (C5:R5), as follows:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim iVal As Integer 'Correcct
Dim myRange As Range 'Correct
Set myRange = Application.ActiveWorkbook.Sheets("CountPeriods").Range("C5:R5")
iVal = Application.WorksheetFunction.CountIf(myRange, "AC") Or Application.WorksheetFunction.CountIf(myRange, "ZAM") Or Application.WorksheetFunction.CountIf(myRange, "ZS") _
Or Application.WorksheetFunction.CountIf(myRange, "SF") Or Application.WorksheetFunction.CountIf(myRange, "LJ") Or Application.WorksheetFunction.CountIf(myRange, "NL") _
Or Application.WorksheetFunction.CountIf(myRange, "LM") Or Application.WorksheetFunction.CountIf(myRange, "AMJ") Or Application.WorksheetFunction.CountIf(myRange, "AMV") _
Or Application.WorksheetFunction.CountIf(myRange, "VN") Or Application.WorksheetFunction.CountIf(myRange, "MN") Or Application.WorksheetFunction.CountIf(myRange, "NQ") _
Or Application.WorksheetFunction.CountIf(myRange, "SR") Or Application.WorksheetFunction.CountIf(myRange, "GS") Or Application.WorksheetFunction.CountIf(myRange, "DS") _
Or Application.WorksheetFunction.CountIf(myRange, "CS") Or Application.WorksheetFunction.CountIf(myRange, "PS") Or Application.WorksheetFunction.CountIf(myRange, "JT") _
Or Application.WorksheetFunction.CountIf(myRange, "MY")
If iVal > 1 Then
On Error Resume Next
MsgBox "This teacher had ALREADY been entered once!"
Selection.Offset(0, -1).ClearContents
Selection.Offset(0, -1).Select
Exit Sub
End If
End Sub
Please help.
Thanks in advance.