• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

VBA code for locking and unlocking cell ranges in execl

NP1872

New Member
I have a code to lock 2 columns completely using vba. However, this locks all other columns. I would like a user to be able to edit and update the other columns and rows with data (the unlocked ones). The problem is that this can only be done by unlocking the cells manually. Is there a vba code that can be run to unlock the cells that need to be populated manually, instead of doing this each time on numerous sheets.
 

Attachments

  • Comments sheet.xlsx
    13.9 KB · Views: 6
Do You mean that every B5-cell in Your Excel-file should be locked?
Hi there, apologies if not clear.

Essentially I am looking for a code the locks certain ranges that has data and allows a user the input ranges that done have data, i.e in the blank cells. The code below is protecting the whole sheet as opposed to the locked ranges only.

>>> use code - tags <<<
Code:
Sub Protectmydata()
Dim strPassword As String
Range("A1:B40").Select
Selection.Locked = True
strPassword = InputBox("Please enter password")
ActiveSheet.Protect Password:=strPassword
End Sub
 
Last edited by a moderator:

NP1872


You wrote:
Is there a vba code that can be run to unlock the cells that need to be populated manually

What is Your certain range,
... where users can input in the blank cells?
... is somewhere a list or so about those cells?

Above will make also that
... after user has inputted something in the blank cell ... those cells cannot input or modify anymore - okay?
 

NP1872


You wrote:
Is there a vba code that can be run to unlock the cells that need to be populated manually

What is Your certain range,
... where users can input in the blank cells?
... is somewhere a list or so about those cells?

Above will make also that
... after user has inputted something in the blank cell ... those cells cannot input or modify anymore - okay?
The range where input should be allowed is column C to E. Once the user has input the data, I would like 2options for the blank cells
- that it can still be modified.
- that it cannot be modified.
This would really assist me greatly.
 

NP1872

Do You really mean so?
With columns C to E ...
... after user has input something
each time with blank cell ... user have to choose someway ... can user modify it (blank cell) or not?
Here is a sample file.
You've written something like this.
Is this something - what do You really would like to have?
 

Attachments

  • NP1872.xlsb
    22.8 KB · Views: 2
Last edited:

NP1872

Do You really mean so?
With columns C to E ...
... after user has input something
each time with blank cell ... user have to choose someway ... can user modify it (blank cell) or not?
Here is a sample file.
You've written something like this.
Is this something - what do You really would like to have?
Thanks for this, much appreciated. It does not fully address what I wanted though. I am generating a report on comments using a VBA subroutine. When the comments are generated each time on a sheet report, I would like the feature you have shared to work. But it runs into an error. Hope you can help on this:)
1707488149364.png
 
Of course, it would be do something 'quick' based above snapshot, but that won't be any solution.
Same kind of effect could get by deleting those Your asked codes away.
Yours It does not fully address what I wanted though.
... but it works as You wrote.
It works with Your given a sample file,
which should be as near as possible with Your normal used file.
If You've there something else --- that matters too.
Yours When the comments are generated each time on a sheet report
For my eyes, above sentence means ... different than Your original 'written-thought'.
>> Without a realistic sample Excel-file this something would be pure guessing. <<
 
Back
Top