Я получаю сообщение об ошибке 1004 для этой строки в редакторе макросов VBA:
If ActiveCell.Name.Name = "DayShift" Or ActiveCell.Name.Name = "AfterShift" Then
Кто-нибудь знает почему? Это весь мой макрос:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim col As Integer
col = ActiveCell.Column
Dim bValue As String
Dim cValue As String
'Check if cell is required to have both columns with value.
'If it is, skip checks.
If ActiveCell.Name.Name = "DayShift" Or ActiveCell.Name.Name = "AfterShift" Then
End
End If
'Check if active column is column B.
If ColLetter(col) = "B" Then
'Format value of active cell.
cValue = "C" + Str(ActiveCell.Row)
cValue = Replace(cValue, " ", "")
'Check if cell has value.
If Range(cValue) = vbNullString Then
'If it does, remove the opposite shift.
Else
MsgBox "This employee has already been assigned for the afternoon shift. In order to allow this change, this employee's scheduling for the afternoon shift will be removed.", vbExclamation
Range(cValue).ClearContents
End If
'Check if active column is column C.
ElseIf ColLetter(col) = "C" Then
'Format value of active cell.
bValue = "B" + Str(ActiveCell.Row)
bValue = Replace(bValue, " ", "")
'Check if cell has value.
If Range(bValue) = vbNullString Then
'If it does, remove the opposite shift.
Else
MsgBox "This employee has already been assigned for the day shift. In order to allow this change, this employee's scheduling for the day shift will be removed.", vbExclamation
Range(bValue).ClearContents
End If
End If
End Sub
Function ColLetter(ColNumber As Integer) As String
ColLetter = Left(Cells(1, ColNumber).Address(False, False), _
1 - (ColNumber > 26))
End Function