когда в файле снята защита листа от изменений, внутренний макрос работает корректно.
Цель макроса - записать в определенную ячейку (исходя из набора правил) текущую дату.
Нужно защитить те ячейки, куда макрос пишет дату от изменений "вручную", что бы ячейка была запрещена на редактирование, но макрос мог в эту ячейку записывать данные.
В файле макрос пишет в ячейки: P65 - SZ66.
Текущий код макроса:
[vba]
Код
Private Sub Worksheet_Change(ByVal Target As Range) Dim col As Long: col = Target.Column If Target.Count > 1 Then Exit Sub If Intersect(Range("P8:SZ9,P63:SZ64,P67:SZ68"), Target) Is Nothing Then Exit Sub Application.ScreenUpdating = False Application.EnableEvents = False If Cells(8, col) <> "" And Cells(9, col) <> "" And _ Cells(63, col) <> "" And Cells(64, col) <> "" Then Cells(65, col) = Date Else Cells(65, col) = "" End If If Cells(8, col) <> "" And Cells(9, col) <> "" And _ Cells(67, col) <> "" And Cells(68, col) <> "" Then Cells(66, col) = Date Else Cells(66, col) = "" End If Application.EnableEvents = True Application.ScreenUpdating = True End Sub
[/vba]
Ошибка возникает именно при попытке макроса записать в защищенную от редактирования ячейку.
Файл у меня большой 400 КБ и версия excel 2010, потому приложить файл не могу
когда в файле снята защита листа от изменений, внутренний макрос работает корректно.
Цель макроса - записать в определенную ячейку (исходя из набора правил) текущую дату.
Нужно защитить те ячейки, куда макрос пишет дату от изменений "вручную", что бы ячейка была запрещена на редактирование, но макрос мог в эту ячейку записывать данные.
В файле макрос пишет в ячейки: P65 - SZ66.
Текущий код макроса:
[vba]
Код
Private Sub Worksheet_Change(ByVal Target As Range) Dim col As Long: col = Target.Column If Target.Count > 1 Then Exit Sub If Intersect(Range("P8:SZ9,P63:SZ64,P67:SZ68"), Target) Is Nothing Then Exit Sub Application.ScreenUpdating = False Application.EnableEvents = False If Cells(8, col) <> "" And Cells(9, col) <> "" And _ Cells(63, col) <> "" And Cells(64, col) <> "" Then Cells(65, col) = Date Else Cells(65, col) = "" End If If Cells(8, col) <> "" And Cells(9, col) <> "" And _ Cells(67, col) <> "" And Cells(68, col) <> "" Then Cells(66, col) = Date Else Cells(66, col) = "" End If Application.EnableEvents = True Application.ScreenUpdating = True End Sub
[/vba]
Ошибка возникает именно при попытке макроса записать в защищенную от редактирования ячейку.
Файл у меня большой 400 КБ и версия excel 2010, потому приложить файл не могу
varikvn, нужно разрешить макросу править ячейки [vba]
Код
Const PWD = "222"
Sub Worksheet_activate() Me.Protect Password:=PWD, UserInterfaceOnly:=1 End Sub
Private Sub Worksheet_Change(ByVal Target As Range) Worksheet_activate Dim col As Long: col = Target.Column If Target.Count > 1 Then Exit Sub If Intersect(Range("P8:SZ9,P63:SZ64,P67:SZ68"), Target) Is Nothing Then Exit Sub Application.ScreenUpdating = False Application.EnableEvents = False If Cells(8, col) <> "" And Cells(9, col) <> "" And _ Cells(63, col) <> "" And Cells(64, col) <> "" Then Cells(65, col) = Date Else Cells(65, col) = "" End If If Cells(8, col) <> "" And Cells(9, col) <> "" And _ Cells(67, col) <> "" And Cells(68, col) <> "" Then Cells(66, col) = Date Else Cells(66, col) = "" End If Application.EnableEvents = True Application.ScreenUpdating = True End Sub
[/vba]
пароль 222
кросс не посмотрел, там уже все расписано оказывается, ну да ладно пусть здесь тоже будет
varikvn, нужно разрешить макросу править ячейки [vba]
Код
Const PWD = "222"
Sub Worksheet_activate() Me.Protect Password:=PWD, UserInterfaceOnly:=1 End Sub
Private Sub Worksheet_Change(ByVal Target As Range) Worksheet_activate Dim col As Long: col = Target.Column If Target.Count > 1 Then Exit Sub If Intersect(Range("P8:SZ9,P63:SZ64,P67:SZ68"), Target) Is Nothing Then Exit Sub Application.ScreenUpdating = False Application.EnableEvents = False If Cells(8, col) <> "" And Cells(9, col) <> "" And _ Cells(63, col) <> "" And Cells(64, col) <> "" Then Cells(65, col) = Date Else Cells(65, col) = "" End If If Cells(8, col) <> "" And Cells(9, col) <> "" And _ Cells(67, col) <> "" And Cells(68, col) <> "" Then Cells(66, col) = Date Else Cells(66, col) = "" End If Application.EnableEvents = True Application.ScreenUpdating = True End Sub
[/vba]
пароль 222
кросс не посмотрел, там уже все расписано оказывается, ну да ладно пусть здесь тоже будетSancho