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
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
When you protect the sheets you probably have the Select unlocked cells option unchecked
1640289693103.png
 
Upvote 0
I hope the placement of hidesheets and protect sheet are in the right line in the macro.
Rich (BB code):
ActiveSheet.Unprotect Password:=123
    ActiveSheet.Shapes.Range(Array("Button 5")).Select
    ActiveSheet.Shapes("Button 5").ZOrder msoSendBackward
    Range("K9").Select
    ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
HideSheets
ActiveSheet.Protect Password:=123

End Sub
 
Upvote 0
The password would normally be on the same line as the rest of the protect code
VBA Code:
    ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True, Password:="123"
    ActiveSheet.EnableSelection = xlNoRestrictions
 HideSheets

Although I have no idea what sheet is active at the time the code is run
 
Upvote 0
The password would normally be on the same line as the rest of the protect code
VBA Code:
    ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True, Password:="123"
    ActiveSheet.EnableSelection = xlNoRestrictions
 HideSheets

Although I have no idea what sheet is active at the time the code is run
All the other 9 sheets including Sheet "Original" is active when I run the code. As I said, the hide and unhide part is working correctly. But, the problem is, after I run the second code, in the end the sheet Original which has unprotected cells get protected. Every time when I have to generate xml I have to unprotect the sheet to paste the data. I need help in editing the code for the cells to stay unprotected so that I can paste data in those cells without unprotecting it each time.
 
Upvote 0
Mark for your reference I am sharing the link so that you can understand better. FYI I have been using this on different data till now successfully. When the user works on this workbook, I want only the sheet Original to display. The rest of the work is done by the code.
 
Upvote 0
Sorry, sent the wrong non working link. This is the right link. The code is slow. It takes 2 minutes to run each macro. When I try to paste the second data to generate xml. it displays that the sheet is protected and hence I can't paste the data without protecting it.
 
Upvote 0
Original Sheet is the only sheet active. But when I run the macro, the code activates all the other sheets for the macro to run through and get the result.
 
Upvote 0

Forum statistics

Threads
1,214,865
Messages
6,121,988
Members
449,060
Latest member
mtsheetz

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