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
 
and I have just downloaded it again and the line is still there
 
Upvote 0

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Sorry Mark. Last 3 Days I am going mad trying to solve this. I am sharing the right code link now.
 
Upvote 0
I get no error running that file if I run the ClearContents macro then click the GenerateXLM button and Bank.XLM was created
 
Upvote 0
Exactly. Now copy the data in original to another sheet, clear the contents of Original and try to paste back the data, it will show that the sheet is protected. Add additional rows in the new data before pasting. It won't accept.
 
Upvote 0
Your cells are locked when I download it so of course they remain the same later. I am going to have to leave this thread now as being Xmas Eve I have things to get on with.
 
Upvote 0
Your cells are locked when I download it so of course they remain the same later. I am going to have to leave this thread now as being Xmas Eve I have things to get on with.
That is what I want to know. Why are the unlocked cells getting locked. Have a Merry Christmas Mark. Till then I will wait for the solution.
 
Upvote 0
That is what I want to know. Why are the unlocked cells getting locked. Have a Merry Christmas Mark. Till then I will wait for the solution.
They are Not unlocked in the download, they are locked, the only unlocked column is column J
 
Upvote 0
They are Not unlocked in the download, they are locked, the only unlocked column is column J
How do I overcome this problem? I tried every possible way to keep the cells in Column A:J unlocked. I don't know where I have gone wrong.
 
Upvote 0
Only way I see it is I will have to keep the macro button in another sheet and protect that sheet. The original sheet will stay like a normal sheet.
 
Upvote 0
The cells in Workbook "Right codes" Sheets("Original") are not unlocked in columns A:I in the file that you uploaded before I run anything, they are LOCKED. It is only Column J that has cells unlocked.

Columns("A:I") are locked at the start and so they will be locked at the finish.
 
Upvote 0
Solution

Forum statistics

Threads
1,215,020
Messages
6,122,712
Members
449,093
Latest member
Mnur

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