Unprotect and reprotect worksheet

Jo4x4

Board Regular
Joined
Jan 8, 2011
Messages
136
Hi everybody,

I am currently using the following code to copy certain data to another worksheet. This works fine if the destination sheet is not protected. What code do I need to add to unprotect and then reprotect the destination sheet?


Code:
Private Sub Worksheet_Change(ByVal Target As Range)

    Const sOrig As String = "Results" '<- Base sheet
    Const sNew As String = "Published results"  '<- Destination sheet
    Const CopyCols As String = "b:L"  '<- Columns to copy
    Const sCopyRows As String = "3:60" '<- Rows to copy
    
    With ActiveSheet
        If .Name = sOrig Then
            Application.ScreenUpdating = False
            
            Intersect(.UsedRange, .Columns(CopyCols), .Rows(sCopyRows)).Copy _
                Destination:=Sheets(sNew).Range("B3")
            Sheets(sOrig).Select
            Application.ScreenUpdating = True
        End If
    End With
End Sub

Thanks
Jo

Win XP, Office 2007
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
By adding:
Rich (BB code):
            Sheets(sNew).Unprotect "Password"
            Intersect(.UsedRange, .Columns(CopyCols), .Rows(sCopyRows)).Copy _
                Destination:=Sheets(sNew).Range("B3")
            Sheets(sNew).Protect "Password"
 
Upvote 0

Forum statistics

Threads
1,224,587
Messages
6,179,734
Members
452,939
Latest member
WCrawford

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