Sheet protected error

sound

New Member
Joined
Jun 23, 2015
Messages
1
Hello folks,

I´m not so talented in writing macros and I´ve spending the last few days trying to understand what´s happening...

I have 3 sheets in a workbook. Sheet1 and Sheet2 are protected Sheet3 don´t.

Sheet1 contains the button that triggers the macro and the data to be stored in Sheet2.

When all the sheets are unprotected the macro works fine but when I protected sheet1 it fails. Even with sheet2 unprotected!!

Error: 1004. The cell you´re trying to change to change is on a protected sheet. And it highlights .End(xlDown).Offset(1, 0).Value = Worksheets("Sheet1").Range("E38").

Note: OP is a excel Table.

Can someone help me?

Code:
Sub Nota()
      
    With Worksheets("Sheet2").Range("OP")
        
        .End(xlDown).Offset(1, 0).Value = Worksheets("Sheet1").Range("E38")
        .End(xlDown).Offset(0, 1).Value = Worksheets("Sheet1").Range("G38")
        .End(xlDown).Offset(0, 2).Value = UCase(Worksheets("Sheet1").Range("C41"))
        .End(xlDown).Offset(0, 4).Value = UCase(Worksheets("Sheet1").Range("E41"))
        .End(xlDown).Offset(0, 5).Value = Worksheets("Sheet1").Range("G41")
    
    End With
    Range("E38,G38,C41,E41,G41").ClearContents
    
    
End Sub
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.

Trebor76

Well-known Member
Joined
Jul 23, 2007
Messages
4,945
Hi sound,

Welcome to MrExcel!!

Try this - just substitute the text YourPasswordHere with whatever you've to protect Sheet1 and Sheet2:

Code:
Option Explicit
Sub Nota()
      
    With Worksheets("Sheet2")
    
        .Unprotect Password:="YourPasswordHere"
        
        With .Range("OP")
        
            .End(xlDown).Offset(1, 0).Value = Worksheets("Sheet1").Range("E38")
            .End(xlDown).Offset(0, 1).Value = Worksheets("Sheet1").Range("G38")
            .End(xlDown).Offset(0, 2).Value = UCase(Worksheets("Sheet1").Range("C41"))
            .End(xlDown).Offset(0, 4).Value = UCase(Worksheets("Sheet1").Range("E41"))
            .End(xlDown).Offset(0, 5).Value = Worksheets("Sheet1").Range("G41")
            
        End With
        
        .Protect Password:="YourPasswordHere"
    
    End With
    
    With Worksheets("Sheet1")
    
        .Unprotect Password:="YourPasswordHere"
    
        .Range("E38,G38,C41,E41,G41").ClearContents
        
        .Protect Password:="YourPasswordHere"
        
    End With
    
End Sub

Regards,

Robert
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,553
Messages
5,832,436
Members
430,133
Latest member
gerasimos

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