Run-Time error '1004' Application-defined or object-defined error

mlee3

Board Regular
Joined
May 6, 2008
Messages
70
Hello. The follow codes worked before I protected the sheet. However, the job stopped in the red statement and pop up the Run-Time error '1004' after I protected the worksheet. Can anyone please help? I highly appreciate!

Private Sub Worksheet_Change(ByVal Target As Range)
ThisWorkbook.Worksheets("test").Protect Password:="test", UserinterfaceOnly:=True



Dim LRow As Integer
LRow = Sheets("draft").Range("A65536").End(xlUp).Row
ActiveWorkbook.Names("GroupName").Delete
Sheets("draft").Range("A2:A" & LRow).Name = "GroupName"
Range("L" & ActiveCell.Row).ClearContents
With Range("L" & ActiveCell.Row)
With .Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:="=GroupName"
End With
End With

End Sub
 

Some videos you may like

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result

Jim885

Well-known Member
Joined
Jul 8, 2012
Messages
663
VBA code does not run when sheets are protected and cells are locked.
 

Jim885

Well-known Member
Joined
Jul 8, 2012
Messages
663
Change your second line to .UnProtect, not .Protect.

Then, put this line of code AFTER the last End With and above End sub


Code:
ThisWorkbook.Worksheets("test").Protect Password:="test", UserinterfaceOnly:=True
 

mlee3

Board Regular
Joined
May 6, 2008
Messages
70
Thank you very much! Your codes did not make it work exactly what I want but I adjusted and figured it out based on your input.
 

Watch MrExcel Video

Forum statistics

Threads
1,122,519
Messages
5,596,635
Members
414,083
Latest member
Mrsash

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top