Unprotect selected columns permanently

RAJESH1960

Banned for repeated rules violations
Joined
Mar 26, 2020
Messages
2,313
Office Version
  1. 2019
Platform
  1. Windows
Hello guys, I am able to hide and unhide the sheets when I run the code. The sheet (Original) I am supposed to enter a new data every time, to generate XML is protected and only the columns (A:J) where I am supposed to paste the data are unlocked. I have already unlocked the cells of those rows and protected the rest of the columns with a password. I have no idea why are the unprotected cells getting locked when I run the macro. I need your expert help to find the solution to solve this problem.

VBA Code:
Option Explicit
Sub HideSheets()
    Dim ws As Worksheet
    ThisWorkbook.Unprotect Password:=123
    For Each ws In ThisWorkbook.Worksheets
        If ws.Name <> "Original" Then
            ws.Protect Password:=123
            ws.Visible = xlSheetVeryHidden
        End If
    Next ws
    ThisWorkbook.Protect Password:=123
End Sub


Sub UnHideSheets()
    Dim ws As Worksheet
    ThisWorkbook.Unprotect Password:=123
    For Each ws In ThisWorkbook.Worksheets
        If ws.Name <> "Original" Then
            ws.Visible = xlSheetVisible
            
        End If
    Next ws
    
End Sub
 
I'm just leaving for work so I'll look at your file once I get back if you have uploaded one where the VBA Project is not protected
 
Upvote 0

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
I'm just leaving for work so I'll look at your file once I get back if you have uploaded one where the VBA Project is not protected
The unprotect password of the VBA Project is also 123. I too have to leave now. We will discuss this tonight and try to solve it.
 
Upvote 0
Just had a look at this at work....
I get an error if I run your ClearContents code from scratch as Sheets("Bank") and Sheets("A") are protected.
The cells on Sheet("Original") don't get locked or Protected for me if I comment out your code above the protection part of the code (I did move the password to be with the rest of the protect code).
If you mean the error you get when you run the code GenerateXML from the button, it is because Sheets("Bank"), Sheets("A") and Sheets("B") are protected when you do the pastespecial.
Your code is slow because you use Select so often.
 
Last edited:
Upvote 0
Just had a look at this at work....
I get an error if I run your ClearContents code from scratch as Sheets("Bank") and Sheets("A") are protected.
The cells on Sheet("Original") don't get locked or Protected for me if I comment out your code above the protection part of the code (I did move the password to be with the rest of the protect code).
If you mean the error you get when you run the code GenerateXML from the button, it is because Sheets("Bank"), Sheets("A") and Sheets("B") are protected when you do the pastespecial.
Your code is slow because you use Select so often.
Did you try the link in post #8.? That is the working one. I don't get any error for the first xml, but when I try to use the same sheet for the next data the original sheet is protected automatically - even the unprotected cells where I need to paste the data.
 
Upvote 0
What should I do to stop the hidden sheets from protection
Remove
VBA Code:
ws.Protect Password:=123

Edit: and yes I was using the file from post 8 and I have downloaded it again with exactly the same results
 
Upvote 0
Rich (BB code):
Option Explicit

Sub HideSheets()
    Dim ws As Worksheet
    ThisWorkbook.Unprotect Password:=123
    For Each ws In ThisWorkbook.Worksheets
        If ws.Name <> "Original" Then
        ws.Visible = xlSheetVeryHidden
        End If
    Next ws
    
End Sub

Sub UnHideSheets()
    Dim ws As Worksheet
    ThisWorkbook.Unprotect Password:=123
    For Each ws In ThisWorkbook.Worksheets
        If ws.Name <> "Original" Then
            ws.Visible = xlSheetVisible
            
        End If
    Next ws
    
End Sub
It is unprotect....in both
 
Upvote 0
The code I see is
Rich (BB code):
Sub HideSheets()
    Dim ws As Worksheet
    ThisWorkbook.Unprotect Password:=123
    For Each ws In ThisWorkbook.Worksheets
        If ws.Name <> "Original" Then
            ws.Protect Password:=123
            ws.Visible = xlSheetVeryHidden
        End If
    Next ws
    ThisWorkbook.Protect Password:=123
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,885
Messages
6,122,090
Members
449,065
Latest member
Danger_SF

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