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 to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
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
 
Upvote 0

Forum statistics

Threads
1,214,874
Messages
6,122,034
Members
449,061
Latest member
TheRealJoaquin

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
Back
Top