Home » excel » excel – VBA Allow to copy only visible cells in a protect sheet

excel – VBA Allow to copy only visible cells in a protect sheet

Posted by: admin May 14, 2020 Leave a comment


I have a protected sheet with the options below and this sheet contains some hidden rows / columns.

        ThisWorkbook.Sheets(ws.Name).EnableOutlining = True
        ThisWorkbook.Sheets(ws.Name).Protect password, _
            AllowFormattingColumns:=True, _
            AllowFormattingRows:=True, _
            userInterfaceOnly:=True, _
            contents:=True, _

And I use this code to block sheets but I want to allow users to also copy only visible cells (using alt +; for example).

I saw the Microsoft website with the documentation (already posted by @Mech), but I tested the options and none worked except the option Contents:= False, but this option set to False allows the user to copy only visible cells edit the contents of the cells (which I don’t want to happen).

Does anyone know any other way?

Thanks in advance!

How to&Answers:

This code should do what you are looking for based on unprotecting the cells for copying purposes.

ActiveSheet.Unprotect Password:="password"
ActiveSheet.Protect Password:="password", DrawingObjects:=True, Contents:=True, Scenarios:=True

src: https://www.mrexcel.com/board/threads/copy-only-visible-cells-on-protected-sheet-book.412461/