Мне нужна помощь в консолидации этого кода Excel, чтобы избежать слишком большой ошибки VBA - PullRequest
0 голосов
/ 04 мая 2020

Я получаю процедуру слишком большой ошибки и, основываясь на данных, я не вижу, как это консолидировать. Можно ли сделать подпункт по столбцам или вы можете помочь мне понять, как его консолидировать? Мои данные практически одинаковы для всех, чтобы создать график, который не допускает перекрытия. Каждый день - это столбец с воскресенья, являющийся столбцом от «B» до субботы столбца «H»

Спасибо

Sub Worksheet_Change(ByVal Target As Range)
If (Range("B6") > 0) And (Range("B6") <> "CSG" And (Range("B6") = Range("B12") And (Range("B6") = Range("B19") And (Range("B6") = Range("B21") And (Range("B6") = Range("B36")))))) Then
MsgBox "You can't have one Security Guard be OmniPresent on the 1st Shift"
Else
If (Range("B6") > 0) And (Range("B6") <> "CSG" And (Range("B6") = Range("B12") And (Range("B6") = Range("B19") And (Range("B6") = Range("B21"))))) Then
MsgBox "You have the same guard at the West Lobby, 1st Shift Dispatch and in Both 1st Shift Mobile Positions"
Else
If (Range("B6") > 0) And (Range("B6") <> "CSG" And (Range("B6") = Range("B12") And (Range("B6") = Range("B19") And (Range("B6") = Range("B36"))))) Then
MsgBox "You have the same guard at the West Lobby, 1st Shift Dispatch, 1st Shift Mobile 1 Position and 1st Shift Bella Vista"
Else
If (Range("B6") > 0) And (Range("B6") <> "CSG" And (Range("B6") = Range("B12") And (Range("B6") = Range("B21") And (Range("B6") = Range("B36"))))) Then
MsgBox "You have the same guard at the West Lobby, 1st Shift Dispatch, 1st Shift Mobile 2 Position and 1st Shift Bella Vista"
Else
If (Range("B6") > 0) And (Range("B6") <> "CSG" And (Range("B6") = Range("B12") And (Range("B6") = Range("B19")))) Then
MsgBox "You have the same guard at the 1st Shift West Lobby, 1st Shift Dispatch and 1st Shift Mobile 1"
Else
If (Range("B6") > 0) And (Range("B6") <> "CSG" And (Range("B6") = Range("B12") And (Range("B6") = Range("B21")))) Then
MsgBox "You have the same guard at the West Lobby, 1st Shift Dispatch and 1st Shift Mobile 2"
Else
If (Range("B6") > 0) And (Range("B6") <> "CSG" And (Range("B6") = Range("B12"))) Then
MsgBox "You have an overlap of 1st Shift Dispatch & 1st shift West Lobby"
Else
If (Range("B6") > 0) And (Range("B6") <> "CSG" And (Range("B6") = Range("B19"))) Then
MsgBox "You have an overlap of 1st Shift West Lobby & 1st shift Mobile 1"
Else
If (Range("B6") > 0) And (Range("B6") <> "CSG" And (Range("B6") = Range("B21"))) Then
MsgBox "You have an overlap of 1st Shift Mobile 2 & 1st shift West Lobby"
Else
If (Range("B6") > 0) And (Range("B6") <> "CSG" And (Range("B6") = Range("B36"))) Then
MsgBox "You have an overlap of 1st Shift Bella Vista & 1st shift West Lobby"
Else
If (Range("B8") > 0) And (Range("B8") <> "CSG" And (Range("B8") = Range("B12") And (Range("B8") = Range("B19") And (Range("B8") = Range("B21") And (Range("B8") = Range("B36")))))) Then
MsgBox " You have the same guard in the 2nd Shift West Lobby, 1st Shift Dispatch, Both 1st Shift Mobile Positions and the 1st shift Bella Vista Position"
Else
If (Range("B8") > 0) And (Range("B8") <> "CSG" And (Range("B8") = Range("B12") And (Range("B8") = Range("B19") And (Range("B8") = Range("B21"))))) Then
MsgBox "You have the same guard in the 2nd Shift West Lobby, 1st Shift Dispatch, Both 1st Shift Mobile Positions"
Else
If (Range("B8") > 0) And (Range("B8") <> "CSG" And (Range("B8") = Range("B12") And (Range("B8") = Range("B19") And (Range("B8") = Range("B36"))))) Then
MsgBox "You have the same guard in the 2nd Shift West Lobby, 1st Shift Dispatch, 1st Shift Mobile 1 and 1st Shift Bella Vista Positions"
Else
If (Range("B8") > 0) And (Range("B8") <> "CSG" And (Range("B8") = Range("B12") And (Range("B8") = Range("B19")))) Then
MsgBox "You have the same guard in the 2nd Shift West Lobby, 1st Shift Dispatch, and 1st Shift Mobile 1 Positions"
Else
If (Range("B8") > 0) And (Range("B8") <> "CSG" And (Range("B8") = Range("B12") And (Range("B8") = Range("B21")))) Then
MsgBox " You have the same guard in the 2nd Shift West Lobby, 1st Shift Dispatch and 1st Shift Mobile 2 Position"
Else
If (Range("B8") > 0) And (Range("B8") <> "CSG" And (Range("B8") = Range("B14") And (Range("B8") = Range("B36")))) Then
MsgBox " You have the same guard in the 2nd Shift West Lobby, 2nd Shift Dispatch and 1st Shift Bella Vista Positions"
Else
If (Range("B8") > 0) And (Range("B8") <> "CSG" And (Range("B8") = Range("B14"))) Then
MsgBox " You have the same guard in the 2nd Shift West Lobby and the 2nd Shift Dispatch Position"
Else
If (Range("B8") > 0) And (Range("B8") <> "CSG" And (Range("B8") = Range("B12"))) Then
MsgBox " You have the same guard in the 2nd Shift West Lobby and the 1st Shift Dispatch Position"
Else
If (Range("B8") > 0) And (Range("B8") <> "CSG" And (Range("B8") = Range("B19"))) Then
MsgBox " You have the same guard in the 2nd Shift West Lobby and the 1st Shift Mobile 1 Position"
Else
If (Range("B8") > 0) And (Range("B8") <> "CSG" And (Range("B8") = Range("B21"))) Then
MsgBox " You have the same guard in the 2nd Shift West Lobby and the 1st Shift Mobile 2 Position"
Else
If (Range("B8") > 0) And (Range("B8") <> "CSG" And (Range("B8") = Range("B36"))) Then
MsgBox " You have the same guard in the 2nd Shift West Lobby and the 1st Shift Bella Vista Positions"
Else
If (Range("B12") > 0) And (Range("B12") <> "CSG" And (Range("B12") = Range("B19") And (Range("B12") = Range("B21") And (Range("B12") = Range("B24") And (Range("B12") = Range("B26") And (Range("B12") = Range("B36"))))))) Then
MsgBox " You have the same guard in 1st Shift Dispatch as you have in Both 1st and 2nd Shift Mobile Positions as well as the 1st Shift Bella Vista Position"
Else
If (Range("B12") > 0) And (Range("B12") <> "CSG" And (Range("B12") = Range("B19") And (Range("B12") = Range("B21") And (Range("B12") = Range("B24") And (Range("B12") = Range("B36")))))) Then
MsgBox " You have the same guard in 1st Shift Dispatch as you have in Both 1st Shift Mobile Positions and the 2nd Shift Mobile 2 Position as well as the 1st Shift Bella Vista Position"
Else
If (Range("B12") > 0) And (Range("B12") <> "CSG" And (Range("B12") = Range("B19") And (Range("B12") = Range("B21") And (Range("B12") = Range("B26") And (Range("B12") = Range("B36")))))) Then
MsgBox " You have the same guard in 1st Shift Dispatch as you have in Both 1st Shift Mobile Positions and the 2nd Shift Mobile 1 Position as well as the 1st Shift Bella Vista Position"
Else
If (Range("B12") > 0) And (Range("B12") <> "CSG" And (Range("B12") = Range("B19") And (Range("B12") = Range("B21") And (Range("B12") = Range("B36"))))) Then
MsgBox " You have the same guard in the 1st Shift Dispatch position as you have in Both 1st Shift Mobile Positions as well as the 1st Shift Bella Vista Position"
Else
If (Range("B12") > 0) And (Range("B12") <> "CSG" And (Range("B12") = Range("B19") And (Range("B12") = Range("B36")))) Then
MsgBox " You have the same guard in the 1st Shift Dispatch position as you have in the 1st Shift Mobile 1 Position as well as the 1st Shift Bella Vista Position"
Else
If (Range("B12") > 0) And (Range("B12") <> "CSG" And (Range("B12") = Range("B21") And (Range("B12") = Range("B36")))) Then
MsgBox " You have the same guard in the 1st Shift Dispatch position as you have in the 1st Shift Mobile 2 Position as well as the 1st Shift Bella Vista Position"
Else
If (Range("B12") > 0) And (Range("B12") <> "CSG" And (Range("B12") = Range("B19") And (Range("B12") = Range("B24")))) Then
MsgBox " You have the same guard in 1st Shift Dispatch as you have in 1st Shift Mobile 1 and 2nd Shift Mobile 2 Positions "
Else
If (Range("B12") > 0) And (Range("B12") <> "CSG" And (Range("B12") = Range("B19") And (Range("B12") = Range("B26")))) Then
MsgBox " You have the same guard in 1st Shift Dispatch as you have in 1st Shift Mobile 1 and 2nd Shift Mobile 1 Positions "
Else
If (Range("B12") > 0) And (Range("B12") <> "CSG" And (Range("B12") = Range("B21") And (Range("B12") = Range("B24")))) Then
MsgBox " You have the same guard in 1st Shift Dispatch as you have in 1st Shift Mobile 2 and 2nd Shift Mobile 2 Positions "
Else
If (Range("B12") > 0) And (Range("B12") <> "CSG" And (Range("B12") = Range("B21") And (Range("B12") = Range("B26")))) Then
MsgBox " You have the same guard in 1st Shift Dispatch as you have in 1st Shift Mobile 2 and 2nd Shift Mobile 1 Positions "
Else
If (Range("B12") > 0) And (Range("B12") <> "CSG" And (Range("B12") = Range("B26") And (Range("B12") = Range("B36")))) Then
MsgBox " You have the same guard in 1st Shift Dispatch as you have in 2nd Shift Mobile 1 and 1st Shift Bella Vista Positions "
Else
If (Range("B12") > 0) And (Range("B12") <> "CSG" And (Range("B12") = Range("B24") And (Range("B12") = Range("B36")))) Then
MsgBox " You have the same guard in 1st Shift Dispatch as you have in 2nd Shift Mobile 2 and 1st Shift Bella Vista Positions "
Else
If (Range("B12") > 0) And (Range("B12") <> "CSG" And (Range("B12") = Range("B36"))) Then
MsgBox " You have the same guard in the 1st Shift Dispatch position as well as the 1st Shift Bella Vista Position"
Else
If (Range("B12") > 0) And (Range("B12") <> "CSG" And (Range("B12") = Range("B19"))) Then
MsgBox " You have the same guard in the 1st Shift Dispatch position as well as the 1st Shift Mobile 1 Position"
Else
If (Range("B12") > 0) And (Range("B12") <> "CSG" And (Range("B12") = Range("B21"))) Then
MsgBox " You have the same guard in the 1st Shift Dispatch position as well as the 1st Shift Mobile 2 Position"
Else
If (Range("B12") > 0) And (Range("B12") <> "CSG" And (Range("B12") = Range("B24"))) Then
MsgBox " You have the same guard in the 1st Shift Dispatch position as well as the 2nd Shift Mobile 2 Position"
Else
If (Range("B12") > 0) And (Range("B12") <> "CSG" And (Range("B12") = Range("B26"))) Then
MsgBox " You have the same guard in the 1st Shift Dispatch position as well as the 2nd Shift Mobile 1 Position"
Else
If (Range("B14") > 0) And (Range("B14") <> "CSG" And (Range("B14") = Range("B24") And (Range("B14") = Range("B26") And (Range("B14") = Range("B28") And (Range("B14") = Range("B31") And (Range("B14") = Range("B33") And (Range("B14") = Range("B38")))))))) Then
MsgBox " Dispatch cannot fill multiple positions, please remove this person from the other positions assigned or assign a different disptacher"
Else
If (Range("B14") > 0) And (Range("B14") <> "CSG" And (Range("B14") = Range("B24") And (Range("B14") = Range("B26") And (Range("B14") = Range("B28") And (Range("B14") = Range("B31") And (Range("B14") = Range("B33"))))))) Then
MsgBox " Dispatch cannot fill multiple positions, please remove this person from the other positions assigned or assign a different disptacher"
Else
If (Range("B14") > 0) And (Range("B14") <> "CSG" And (Range("B14") = Range("B24") And (Range("B14") = Range("B26") And (Range("B14") = Range("B28") And (Range("B14") = Range("B31")))))) Then
MsgBox " Dispatch cannot fill multiple positions, please remove this person from the other positions assigned or assign a different disptacher"
Else
If (Range("B14") > 0) And (Range("B14") <> "CSG" And (Range("B14") = Range("B24") And (Range("B14") = Range("B26") And (Range("B14") = Range("B28"))))) Then
MsgBox " Dispatch cannot fill multiple positions, please remove this person from the other positions assigned or assign a different disptacher"
Else
If (Range("B14") > 0) And (Range("B14") <> "CSG" And (Range("B14") = Range("B24") And (Range("B14") = Range("B26")))) Then
MsgBox " Dispatch cannot fill multiple positions, please remove this person from the other positions assigned or assign a different disptacher"
Else
If (Range("B14") > 0) And (Range("B14") <> "CSG" And (Range("B14") = Range("B24"))) Then
MsgBox " Dispatch cannot fill multiple positions, please remove this person from the other positions assigned or assign a different disptacher"
If (Range("B16") > 0) And (Range("B16") <> "CSG" And (Range("B16") = Range("B28") And (Range("B16") = Range("B31") And (Range("B16") = Range("B33") And (Range("B16") = Range("B38") And (Range("B16") = Range("B40"))))))) Then
MsgBox " Dispatch cannot fill multiple positions, please remove this person from the other positions assigned during these hours or assign a different disptacher"
Else
If (Range("B16") > 0) And (Range("B16") <> "CSG" And (Range("B16") = Range("B28") And (Range("B16") = Range("B31") And (Range("B16") = Range("B33") And (Range("B16") = Range("B38")))))) Then
MsgBox " Dispatch cannot fill multiple positions, please remove this person from the other positions assigned during these hours or assign a different disptacher"
Else
If (Range("B16") > 0) And (Range("B16") <> "CSG" And (Range("B16") = Range("B28") And (Range("B16") = Range("B31") And (Range("B16") = Range("B33"))))) Then
MsgBox " Dispatch cannot fill multiple positions, please remove this person from the other positions assigned during these hours or assign a different disptacher"
Else
If (Range("B16") > 0) And (Range("B16") <> "CSG" And (Range("B16") = Range("B28") And (Range("B16") = Range("B31")))) Then
MsgBox " Dispatch cannot fill multiple positions, please remove this person from the other positions assigned during these hours or assign a different disptacher"
Else
If (Range("B16") > 0) And (Range("B16") <> "CSG" And (Range("B16") = Range("B40"))) Then
MsgBox " Dispatch cannot fill multiple positions, please remove this person from the 3rd shift Bella Vista position or assign a different disptacher"
Else
If (Range("B16") > 0) And (Range("B16") <> "CSG" And (Range("B16") = Range("B38"))) Then
MsgBox " Dispatch cannot fill multiple positions, please remove this person from 2nd shift Bella Vista position or assign a different disptacher"
Else
If (Range("B16") > 0) And (Range("B16") <> "CSG" And (Range("B16") = Range("B33"))) Then
MsgBox " Dispatch cannot fill multiple positions, please remove this person from 3rd Shift Mobile 2 position or assign a different disptacher"
Else
If (Range("B16") > 0) And (Range("B16") <> "CSG" And (Range("B16") = Range("B31"))) Then
MsgBox " Dispatch cannot fill multiple positions, please remove this person from 3rd Shift Mobile 1 position or assign a different disptacher"
Else
If (Range("B16") > 0) And (Range("B16") <> "CSG" And (Range("B16") = Range("B28"))) Then
MsgBox " Dispatch cannot fill multiple positions, please remove this person from 2nd Shift Mobile 2 position or assign a different disptacher"
If (Range("B19") > 0) And (Range("B19") <> "CSG" And (Range("B19") = Range("B36"))) Then
MsgBox " This overlaps with the 1st Shift Bella Vista Position"
Else
If (Range("B19") > 0) And (Range("B19") <> "CSG" And (Range("B19") = Range("B24"))) Then
MsgBox " This position overlaps with the 2st Shift Mobile 2 Position by 30 mintues."
Else
If (Range("B21") > 0) And (Range("B21") <> "CSG" And (Range("B21") = Range("B36"))) Then
MsgBox " This overlaps with the 1st Shift Bella Vista Position"
Else
If (Range("B26") > 0) And (Range("B26") <> "CSG" And (Range("B26") = Range("B38"))) Then
MsgBox " This overlaps with the 2nd Shift Bella Vista Position"
Else
If (Range("B28") > 0) And (Range("B28") <> "CSG" And (Range("B28") = Range("B40"))) Then
MsgBox " This overlaps with the 3nd Shift Bella Vista Position"
Else
End Sub
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...