rcicconetti
New Member
- Joined
- Jan 16, 2016
- Messages
- 34
Can(should) this sub be shortened?
This code is used in a Scheduling workbook to alert the user that there is a scheduling conflict...and it works well, HOWEVER:
This only represents 1 DEPARTMENT for 1 full Day. There are 6 departments scheduled over 14 days, and the all have AM and PM shifts. So the code below would be repeated 168 times with slight variations that will address different ranges.
Is there a more efficient way to write this?
Should I make 168 different subs? Or continue to nest them?
VBA Code:
Original thread and full explanation CAN BE FOUND HERE
This code is used in a Scheduling workbook to alert the user that there is a scheduling conflict...and it works well, HOWEVER:
This only represents 1 DEPARTMENT for 1 full Day. There are 6 departments scheduled over 14 days, and the all have AM and PM shifts. So the code below would be repeated 168 times with slight variations that will address different ranges.
Is there a more efficient way to write this?
Should I make 168 different subs? Or continue to nest them?
VBA Code:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim bFound As Boolean
Dim rCell As Range
bFound = False
'WEDNESDAY AM SERVER
If Not Intersect(Target, Range("WED_AM_SER")) Is Nothing Then
For Each rCell In Sheet2.Range("S11:S800") 'Me refers to the worksheet that the event macro is in.
If Trim(rCell.Value) = Trim(Target.Value) _
Then
bFound = True
Exit For
End If
Next rCell
If Not bFound _
Then
MsgBox "There is an AVAILABILITY CONFLICT with this Employee", vbCritical
End If
End If
'WEDNESDAY PM SERVER
If Not Intersect(Target, Range("WED_PM_SER")) Is Nothing Then
For Each rCell In Sheet2.Range("U11:U800") 'Me refers to the worksheet that the event macro is in.
If Trim(rCell.Value) = Trim(Target.Value) _
Then
bFound = True
Exit For
End If
Next rCell
If Not bFound _
Then
MsgBox "There is an AVAILABILITY CONFLICT with this Employee", vbCritical
End If
End If
Original thread and full explanation CAN BE FOUND HERE