Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 811113
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T00:59:31+00:00 2026-05-15T00:59:31+00:00

I have a protected worksheet that users would like to copy and paste into.

  • 0

I have a protected worksheet that users would like to copy and paste into. I have no control over the workbook they are copying from.

The protected worksheet has some rows that are available for data entry, and other rows that are locked and greyed out to the user. The users would like to be able to paste over the top of the entire worksheet from another random workbook and have all the cells available for data entry filled in, while the locked cells are undisturbed. In the current state, the user gets an error when they try to paste, because it cannot paste over the locked cells.

Example:
Worksheet 1:

Act1 100 100 100
Act2 100 100 100
Act3 100 100 100

Worksheet 2: (The second row is locked)

Act1 300 300 300
Act2 200 200 200
Act3 100 100 100

After copying/pasting Worksheet 2 should look like this:

Act1 100 100 100
Act2 200 200 200
Act3 100 100 100

The values from worksheet 1 are populated and the locked rows are undisturbed.

  • I’ve been thinking along the lines of having a hook where on paste, the locked cells are unlocked so that the paste can happen, and then are reverted to their original values and relocked.
  • Is there some way I can loop through the cells in the clipboard and only paste cells where the target isn’t locked?
  • It is preferable to not create a separate button for paste, so there is less impact on the users, but if that’s the only way, I’m not opposed to it.
  • Currently, I plan on grouping the locked rows together, so that the data entry cells are contiguous, but then the accounts will be out of order, which is not preferred.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T00:59:32+00:00Added an answer on May 15, 2026 at 12:59 am

    Requirements:

    1. Allow pasting into protected sheets
    2. Retain content in the locked cells after paste operation
    3. Retain protection status of the sheet

    Method:

    1. Handle all possible paste operations in user defined module, instead of Excel’s way
    2. Since unprotecting removes contents from clipboard paste to a temp sheet
    3. make a note of user intended paste location
    4. make a note of locked cells in the protected sheet (content and address)
    5. unprotect the sheet
    6. paste to intended cells from temp sheet
    7. remove temp sheet and protect main sheet

    I referred to Jan Karel’s Catch Paste sample for reference. You might want to add all the ways he is catching paste operations.

    In the ThisWorkbook module add below code

    Private mdNextTimeCatchPaste As Double
    
    Private Sub Workbook_Activate()
        REM Add Paste event handler
        CatchPaste
    End Sub
    
    Private Sub Workbook_BeforeClose(Cancel As Boolean)
        REM Restore Paste event handler
        StopCatchPaste
        mdNextTimeCatchPaste = Now
        Application.OnTime mdNextTimeCatchPaste, "'" & ThisWorkbook.Name & "'!UnProtectPasteToSheet"
    End Sub
    
    
    Private Sub Workbook_Deactivate()
        REM Restore Paste event handler
        StopCatchPaste
        On Error Resume Next
        REM Cancel scheduled macroREM s,
        REM because we might be closing the file
        Application.OnTime mdNextTimeCatchPaste, "'" & ThisWorkbook.Name & "'!UnProtectPasteToSheet", , False
    End Sub
    
    Private Sub Workbook_Open()
        REM Add Paste event handler
        CatchPaste
    End Sub
    

    Add a new Module and add below code

    REM Add Paste event handler
    Public Sub CatchPaste()
    REM these are the ways you can Paste in to Excel
    REM refer to http://www.jkp-ads.com/articles/catchpaste.asp for more details
    Application.OnKey "^v", "UnProtectPasteToSheet"
    Application.OnKey "^{Insert}", "UnProtectPasteToSheet"
    Application.OnKey "+{Insert}", "UnProtectPasteToSheet"
    Application.OnKey "~", "UnProtectPasteToSheet"
    Application.OnKey "{Enter}", "UnProtectPasteToSheet"
    End Sub
    REM restore all default events
    Public Sub StopCatchPaste()
    Application.OnKey "^v", ""
    Application.OnKey "^{Insert}", ""
    Application.OnKey "+{Insert}", ""
    Application.OnKey "~", ""
    Application.OnKey "{Enter}", ""
    End Sub
    
    REM Here we will check the sheet is protected, if it is then paste to a temp sheet,
    REM unprotect main sheet, paste the values, and restore locked cells
    Private Sub UnProtectPasteToSheet()
    On Error GoTo ErrHandler
    Dim bProtected As Boolean, oSheet As Worksheet, oTempSheet As Worksheet, sPasteLocation As String
    Dim oCell As Range, oCollAddress As New Collection, oCollValue As New Collection, iCount As Integer
    
    REM check protection status
    If Not ThisWorkbook.ActiveSheet.ProtectContents Then
        Selection.PasteSpecial Paste:=xlAll
    Else
        bProtected = True
        Set oSheet = ThisWorkbook.ActiveSheet
        REM save paste location
        sPasteLocation = Selection.Address
        REM unprotecting clears Clipboard in Excel!! strange but true..
        REM So paste it to a new sheet before unprotecting
        Set oTempSheet = ThisWorkbook.Worksheets.Add
        REM oSheet.Visible = xlSheetVeryHidden
        oTempSheet.Paste
        REM unprotect the sheet
        oSheet.Unprotect
    
        REM make a note of all locked cells
        For Each oCell In oSheet.UsedRange
            If oCell.Locked Then
                oCollAddress.Add oCell.Address
                oCollValue.Add oCell.Value
            End If
        Next
    
        REM paste
        oTempSheet.UsedRange.Copy
        oSheet.Activate
        oSheet.Range(sPasteLocation).Select
        REM you need to paste only values since pasting format will lock all those cells
        REM since in Excel default status is "Locked"
        Selection.PasteSpecial xlValues
    
        REM remove temp sheet
        Application.DisplayAlerts = False
        oTempSheet.Delete
        Application.DisplayAlerts = True
    
        REM restore locked cells
        For iCount = 1 To oCollAddress.Count
            Range(oCollAddress.Item(iCount)) = oCollValue.Item(iCount)
        Next
        REM restore protection
        oSheet.Protect
    
    End If
    Exit Sub
    
    ErrHandler:
        Debug.Print Err.Description
        If bProtected Then
            ThisWorkbook.ActiveSheet.Protect
        End If
    End Sub
    

    Note: I am adding REM instead of ' to keep the Stackoverflow formatter happy.
    Give it a try and let me know how it goes..

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.